Deprecate ExtensionFunctionType on a non-function types

Related to KT-43527
This commit is contained in:
Mikhail Glukhikh
2022-01-12 17:13:37 +03:00
parent d0fa3eb1d3
commit 1274e2b90a
17 changed files with 61 additions and 10 deletions
@@ -279,6 +279,7 @@ public interface Errors {
DiagnosticFactory0<KtAnnotationEntry> REPEATED_ANNOTATION_WARNING = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtAnnotationEntry> NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> WRONG_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> WRONG_EXTENSION_FUNCTION_TYPE_WARNING = DiagnosticFactory0.create(WARNING);
// Annotations
@@ -146,7 +146,8 @@ public class DefaultErrorMessages {
MAP.put(REPEATED_ANNOTATION, "This annotation is not repeatable");
MAP.put(REPEATED_ANNOTATION_WARNING, "This annotation is not repeatable");
MAP.put(NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION, "The lambda expression here is an inlined argument so this annotation cannot be stored anywhere");
MAP.put(WRONG_EXTENSION_FUNCTION_TYPE, "ExtensionFunctionType is forbidden on a function type without parameters");
MAP.put(WRONG_EXTENSION_FUNCTION_TYPE, "ExtensionFunctionType is forbidden on a function type without parameters or on a non-function type");
MAP.put(WRONG_EXTENSION_FUNCTION_TYPE_WARNING, "ExtensionFunctionType makes no sense on a non-function type. It will be an error in a future release.");
MAP.put(INAPPLICABLE_TARGET_ON_PROPERTY, "''@{0}:'' annotations could be applied only to property declarations", TO_STRING);
MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "''@{0}:'' annotations could be applied only to mutable properties", TO_STRING);
@@ -185,9 +185,17 @@ class AnnotationChecker(
}
}
if (descriptor?.annotationClass?.classId == StandardClassIds.Annotations.ExtensionFunctionType) {
val type = trace[BindingContext.TYPE, reference]
if (type != null && type.isFunctionOrKFunctionTypeWithAnySuspendability && type.arguments.size <= 1) {
trace.report(Errors.WRONG_EXTENSION_FUNCTION_TYPE.on(entry))
val type = trace[BindingContext.TYPE, reference] ?: trace[BindingContext.ABBREVIATED_TYPE, reference]
if (type != null) {
if (!type.isFunctionOrKFunctionTypeWithAnySuspendability) {
if (languageVersionSettings.supportsFeature(ForbidExtensionFunctionTypeOnNonFunctionTypes)) {
trace.report(Errors.WRONG_EXTENSION_FUNCTION_TYPE.on(entry))
} else {
trace.report(Errors.WRONG_EXTENSION_FUNCTION_TYPE_WARNING.on(entry))
}
} else if (type.arguments.size <= 1) {
trace.report(Errors.WRONG_EXTENSION_FUNCTION_TYPE.on(entry))
}
}
}
}