diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index a91e1e92061..01bef0f8742 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -206,6 +206,7 @@ public interface Errors { DiagnosticFactory0 INLINE_SUSPEND_FUNCTION_TYPE_UNSUPPORTED = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 WRONG_ANNOTATION_TARGET = DiagnosticFactory1.create(ERROR); DiagnosticFactory2 WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET = DiagnosticFactory2.create(ERROR); + DiagnosticFactory1 WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET_ON_TYPE = DiagnosticFactory1.create(WARNING); DiagnosticFactory0 REPEATED_ANNOTATION = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index d1d3f5c026a..a256f2afc3f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -149,6 +149,8 @@ public class DefaultErrorMessages { MAP.put(INLINE_SUSPEND_FUNCTION_TYPE_UNSUPPORTED, "Inline lambda parameters of suspend function type are not fully supported. Add 'noinline' modifier."); MAP.put(WRONG_ANNOTATION_TARGET, "This annotation is not applicable to target ''{0}''", TO_STRING); MAP.put(WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET, "This annotation is not applicable to target ''{0}'' and use site target ''@{1}''", TO_STRING, TO_STRING); + MAP.put(WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET_ON_TYPE, + "Use of this annotation with target ''type'' and use site target ''@{0}'' is deprecated", TO_STRING); MAP.put(REPEATED_ANNOTATION, "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"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt index 2fea37d0c3b..ee128781bae 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor @@ -38,7 +40,10 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.isError -class AnnotationChecker(private val additionalCheckers: Iterable) { +class AnnotationChecker( + private val additionalCheckers: Iterable, + private val languageVersionSettings: LanguageVersionSettings +) { fun check(annotated: KtAnnotated, trace: BindingTrace, descriptor: DeclarationDescriptor? = null) { val actualTargets = getActualTargetList(annotated, descriptor, trace) @@ -144,15 +149,30 @@ class AnnotationChecker(private val additionalCheckers: Iterable@setparam:Suppress Int) {} -fun test2(i: @param:Suppress Int) {} -fun test3(i: @receiver:Suppress Int) {} -fun test4(i: @field:Suppress Int) {} -fun test5(i: @set:Suppress Int) {} +fun test1(i: @setparam:Suppress Int) {} +fun test2(i: @param:Suppress Int) {} +fun test3(i: @receiver:Suppress Int) {} -fun test6(): @setparam:Suppress Int = TODO() -fun test7(i: (@setparam:Suppress Int) -> Unit) {} +fun test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} -fun @setparam:Suppress Int.test8() {} -fun ((@setparam:Suppress Int) -> Unit).test9() {} +fun ((@setparam:Suppress Int) -> Unit).test6() {} -fun test10(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.txt index 628c159de21..7f4539dbea7 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.txt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.txt @@ -1,12 +1,9 @@ package public fun test1(/*0*/ i: @setparam:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit -public fun test10(): (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit public fun test2(/*0*/ i: @param:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit public fun test3(/*0*/ i: @receiver:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit -public fun test4(/*0*/ i: @field:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit -public fun test5(/*0*/ i: @set:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit -public fun test6(): @setparam:kotlin.Suppress(names = {}) kotlin.Int -public fun test7(/*0*/ i: (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit): kotlin.Unit -public fun @setparam:kotlin.Suppress(names = {}) kotlin.Int.test8(): kotlin.Unit -public fun ((@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit).test9(): kotlin.Unit +public fun test4(): @setparam:kotlin.Suppress(names = {}) kotlin.Int +public fun test5(/*0*/ i: (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit): kotlin.Unit +public fun test7(): (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit +public fun ((@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit).test6(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt new file mode 100644 index 00000000000..41ee053c1e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(i: @setparam:Suppress Int) {} +fun test2(i: @param:Suppress Int) {} +fun test3(i: @receiver:Suppress Int) {} + +fun test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} + +fun ((@setparam:Suppress Int) -> Unit).test6() {} + +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.txt new file mode 100644 index 00000000000..7f4539dbea7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.txt @@ -0,0 +1,9 @@ +package + +public fun test1(/*0*/ i: @setparam:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit +public fun test2(/*0*/ i: @param:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit +public fun test3(/*0*/ i: @receiver:kotlin.Suppress(names = {}) kotlin.Int): kotlin.Unit +public fun test4(): @setparam:kotlin.Suppress(names = {}) kotlin.Int +public fun test5(/*0*/ i: (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit): kotlin.Unit +public fun test7(): (@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit +public fun ((@setparam:kotlin.Suppress(names = {}) kotlin.Int) -> kotlin.Unit).test6(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 61ebe5e9f50..0b56da52ba0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -1688,6 +1688,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.kt"); doTest(fileName); } + + @TestMetadata("wrongParamAnnotationsOnTypesError.kt") + public void testWrongParamAnnotationsOnTypesError() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index c8002830643..cdb2b2dcfde 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -1688,6 +1688,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes.kt"); doTest(fileName); } + + @TestMetadata("wrongParamAnnotationsOnTypesError.kt") + public void testWrongParamAnnotationsOnTypesError() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt"); + doTest(fileName); + } } } diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 6cbde0485ce..9ed153229f3 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -64,6 +64,7 @@ enum class LanguageFeature( RestrictionOfValReassignmentViaBackingField(KOTLIN_1_3), NestedClassesInEnumEntryShouldBeInner(KOTLIN_1_3), + RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes(KOTLIN_1_3), // Experimental features