diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt index 88c68643261..c5828af3317 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt @@ -26,21 +26,17 @@ object FirTypeAnnotationChecker : FirTypeRefChecker() { for (annotation in typeRef.annotations) { if (annotation.source == null) continue val useSiteTarget = annotation.useSiteTarget + val annotationTargets = annotation.getAllowedAnnotationTargets(context.session) - // Annotations with `@receiver:` go + // Annotations like `@receiver:` go // into FirReceiverParameter, not FirTypeRef - if (useSiteTarget == AnnotationUseSiteTarget.RECEIVER) { + if (useSiteTarget != null) { reporter.reportOn( annotation.source, FirErrors.WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET, "type usage", useSiteTarget.renderName, context ) - } - - val annotationTargets = annotation.getAllowedAnnotationTargets(context.session) - if (KotlinTarget.TYPE !in annotationTargets) { - if (useSiteTarget == null || KotlinTarget.USE_SITE_MAPPING[useSiteTarget] !in annotationTargets) { - reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context) - } + } else if (KotlinTarget.TYPE !in annotationTargets) { + reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context) } if (annotation.toAnnotationClassId(context.session) == StandardClassIds.Annotations.ExtensionFunctionType) { if (!typeRef.type.isSomeFunctionType(context.session)) { diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt index 524c3e605dc..4cffa0230e4 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt @@ -6,6 +6,6 @@ fun test1(@@file @Suppress("") fun test2() {} -class OnType(x: @file Suppress("") Int) +class OnType(x: @file Suppress("") Int) -fun @file : Suppress("") Int.test3() {} \ No newline at end of file +fun @file : Suppress("") Int.test3() {} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt index f946ec19e84..7b6999ff9dc 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt @@ -6,6 +6,6 @@ fun test1(@@file @Suppress("") fun test2() {} -class OnType(x: @file Suppress("") Int) +class OnType(x: @file Suppress("") Int) -fun @file : Suppress("") Int.test3() {} \ No newline at end of file +fun @file : Suppress("") Int.test3() {} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt new file mode 100644 index 00000000000..8b8f18d3318 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: -ProhibitUseSiteTargetAnnotationsOnSuperTypes + +interface Foo + +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo + +interface G : @Ann Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.kt index 67118e832af..950df44a179 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !LANGUAGE: -ProhibitUseSiteTargetAnnotationsOnSuperTypes interface Foo diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt new file mode 100644 index 00000000000..e3e6d3d7ac3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes + +interface Foo + +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo + +interface G : @Ann Foo diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt index 4434897a555..549ff18bfe3 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes interface Foo diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt deleted file mode 100644 index c15d326ad13..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -// !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.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt index 41ee053c1e4..9cfe72ac5fd 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt deleted file mode 100644 index c15d326ad13..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -// !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/wrongParamAnnotationsOnTypes_after.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.kt index 41ee053c1e4..9cfe72ac5fd 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt index 012ca2b84da..cab9c82d764 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt @@ -1,13 +1,13 @@ // !LANGUAGE: -RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes // !DIAGNOSTICS: -UNUSED_PARAMETER -fun test1(i: @setparam:Suppress Int) {} -fun test2(i: @param:Suppress Int) {} +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 test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} -fun ((@setparam:Suppress Int) -> Unit).test6() {} +fun ((@setparam:Suppress Int) -> Unit).test6() {} -fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() diff --git a/compiler/testData/diagnostics/tests/kt56769.fir.kt b/compiler/testData/diagnostics/tests/kt56769.fir.kt index 3b6fc425ad7..3e16dd4717f 100644 --- a/compiler/testData/diagnostics/tests/kt56769.fir.kt +++ b/compiler/testData/diagnostics/tests/kt56769.fir.kt @@ -6,7 +6,7 @@ fun Int.train(args: Array<@recei fun Int.plane(@receiver:Anno args: Array) {} -fun vein(args: Array<@file:Anno String>) {} +fun vein(args: Array<@file:Anno String>) {} fun rain(args: Array<@Anno String>) {} @@ -14,6 +14,6 @@ fun @Anno Int.strain() {} fun @receiver:Anno Int.drain() {} -fun @file:Anno Int.brain() {} +fun @file:Anno Int.brain() {} fun (@Anno Int).crane() {}