diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt index 1c0db360a5c..32436d16b6a 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt @@ -22,19 +22,13 @@ internal val annotationPhase = makeIrFilePhase( description = "Remove constructors of annotation classes" ) -/** - * Remove the constructors from annotation classes. - */ private class AnnotationLowering : FileLoweringPass, IrElementTransformerVoid() { override fun lower(irFile: IrFile) = irFile.transformChildrenVoid(this) - override fun visitClass(declaration: IrClass): IrStatement { - if (!declaration.isAnnotationClass) return super.visitClass(declaration) - - declaration.declarations.removeIf { - it is IrConstructor + override fun visitClass(declaration: IrClass): IrStatement = + declaration.transformPostfix { + if (isAnnotationClass) { + declarations.removeIf { it is IrConstructor } + } } - - return declaration - } } diff --git a/compiler/testData/codegen/box/annotations/nestedAnnotation.kt b/compiler/testData/codegen/box/annotations/nestedAnnotation.kt new file mode 100644 index 00000000000..291e6d70a8f --- /dev/null +++ b/compiler/testData/codegen/box/annotations/nestedAnnotation.kt @@ -0,0 +1,8 @@ +annotation class Foo { + annotation class Bar +} + +@Foo.Bar +fun box(): String { + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 5af4acccfda..cfec674664f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassPropertyAsParameter.kt") public void testNestedClassPropertyAsParameter() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9ca6bdb907b..b3dce28991f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -141,6 +141,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassPropertyAsParameter.kt") public void testNestedClassPropertyAsParameter() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index f17e4287a76..0cbe3e088c5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassPropertyAsParameter.kt") public void testNestedClassPropertyAsParameter() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e4cccfcc71c..757dd98ec87 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassPropertyAsParameter.kt") public void testNestedClassPropertyAsParameter() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassPropertyAsParameter.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 510e0b1cfa9..99d57ed9dc7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -41,6 +41,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassesInAnnotations.kt") public void testNestedClassesInAnnotations() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 03738ad9638..0e6c619b1f2 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -41,6 +41,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("nestedAnnotation.kt") + public void testNestedAnnotation() throws Exception { + runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); + } + @TestMetadata("nestedClassesInAnnotations.kt") public void testNestedClassesInAnnotations() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt");