diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.kt new file mode 100644 index 00000000000..20fc13b1970 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.kt @@ -0,0 +1,22 @@ +// FILE: State.java + +package simulation + +@Retention(RetentionPolicy.RUNTIME) +public @interface State { + @NotNull @NonNls + String name(); + String @NotNull [] storages() default {}; +} + +// FILE: KotlinImporterComponent.kt + +package simulation + +// KotlinMavenImporter.kt:407:1 +@State( + name = "AutoImportedSourceRoots" +) +class KotlinImporterComponent { + class State(var directories: List = ArrayList()) +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.txt new file mode 100644 index 00000000000..8df815368a9 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.txt @@ -0,0 +1,18 @@ +FILE: KotlinImporterComponent.kt + @R|State|(name = String(AutoImportedSourceRoots)) public final class KotlinImporterComponent : R|kotlin/Any| { + public constructor(): R|simulation/KotlinImporterComponent| { + super() + } + + public final class State : R|kotlin/Any| { + public constructor(directories: R|kotlin/collections/List| = R|java/util/ArrayList.ArrayList|!|>()): R|simulation/KotlinImporterComponent.State| { + super() + } + + public final var directories: R|kotlin/collections/List| = R|/directories| + public get(): R|kotlin/collections/List| + public set(value: R|kotlin/collections/List|): R|kotlin/Unit| + + } + + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 28819360c1f..5c664cff5aa 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1081,6 +1081,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt"); } + @TestMetadata("testIllegalAnnotationClass.kt") + public void testTestIllegalAnnotationClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.kt"); + } + @TestMetadata("typeArgumentsNotAllowed.kt") public void testTypeArgumentsNotAllowed() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeArgumentsNotAllowed.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 5c70f88cf13..91f176b51b1 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1081,6 +1081,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt"); } + @TestMetadata("testIllegalAnnotationClass.kt") + public void testTestIllegalAnnotationClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/testIllegalAnnotationClass.kt"); + } + @TestMetadata("typeArgumentsNotAllowed.kt") public void testTypeArgumentsNotAllowed() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeArgumentsNotAllowed.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt index ab5236227ea..8e6ac26905d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt @@ -52,6 +52,11 @@ abstract class FirAbstractTreeTransformerWithSuperTypes( data: Nothing? ): CompositeTransformResult { return withScopeCleanup { + // Otherwise annotations may try to resolve + // themselves as inner classes of the `firClass` + // if their names match + firClass.transformAnnotations(this, null) + // ? Is it Ok to use original file session here ? val superTypes = lookupSuperTypes( firClass, @@ -76,6 +81,8 @@ abstract class FirAbstractTreeTransformerWithSuperTypes( nestedClassifierScope(firClass)?.let(scopes::add) + // Note that annotations are still visited here + // again, although there's no need in it transformElement(firClass, data) } }