diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index 6d680217706..448c0d4eb38 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -32,7 +32,6 @@ import org.jetbrains.kotlin.psi.KtEnumEntry import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -286,14 +285,11 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe val classDescriptor = irClass.descriptor val primaryConstructorDescriptor = classDescriptor.unsubstitutedPrimaryConstructor ?: return null - val irPrimaryConstructor = - FunctionGenerator(declarationGenerator).generatePrimaryConstructor(primaryConstructorDescriptor, ktClassOrObject) - - if (!DescriptorUtils.isAnnotationClass(classDescriptor)) { - irClass.addMember(irPrimaryConstructor) - } - - return irPrimaryConstructor + return FunctionGenerator(declarationGenerator) + .generatePrimaryConstructor(primaryConstructorDescriptor, ktClassOrObject) + .also { + irClass.addMember(it) + } } private fun generateDeclarationsForPrimaryConstructorParameters( diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt index 3b37aa975f3..2a007e971f4 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.psi2ir.isConstructorDelegatingToSuper import org.jetbrains.kotlin.psi2ir.startOffsetOrUndefined import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.DescriptorUtils class FunctionGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGeneratorExtension(declarationGenerator) { constructor(context: GeneratorContext) : this(DeclarationGenerator(context)) @@ -198,7 +199,10 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktClassOrObject: KtClassOrObject ): IrConstructor = declareConstructor(ktClassOrObject, ktClassOrObject.primaryConstructor ?: ktClassOrObject, primaryConstructorDescriptor) { - if (primaryConstructorDescriptor.isExpect) + if ( + primaryConstructorDescriptor.isExpect || + DescriptorUtils.isAnnotationClass(primaryConstructorDescriptor.constructedClass) + ) null else generatePrimaryConstructorBody(ktClassOrObject) diff --git a/compiler/testData/ir/irText/classes/annotationClasses.kt b/compiler/testData/ir/irText/classes/annotationClasses.kt new file mode 100644 index 00000000000..ebcb48a4829 --- /dev/null +++ b/compiler/testData/ir/irText/classes/annotationClasses.kt @@ -0,0 +1,7 @@ +annotation class Test1(val x: Int) + +annotation class Test2(val x: Int = 0) + +annotation class Test3(val x: Test1) + +annotation class Test4(vararg val xs: Int) \ No newline at end of file diff --git a/compiler/testData/ir/irText/classes/annotationClasses.txt b/compiler/testData/ir/irText/classes/annotationClasses.txt new file mode 100644 index 00000000000..026e2d570d9 --- /dev/null +++ b/compiler/testData/ir/irText/classes/annotationClasses.txt @@ -0,0 +1,119 @@ +FILE fqName: fileName:/annotationClasses.kt + CLASS ANNOTATION_CLASS name:Test1 modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test1 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:Annotation modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:Test1 flags: + VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: + PROPERTY name:x type:kotlin.Int visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public + EXPRESSION_BODY + GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test1) returnType:Int flags: + $this: VALUE_PARAMETER name: type:Test1 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_FIELD 'x: Int' type=kotlin.Int origin=null + receiver: GET_VAR 'this@Test1: Test1' type=Test1 origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + overridden: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + overridden: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS ANNOTATION_CLASS name:Test2 modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test2 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:Annotation modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:Test2 flags: + VALUE_PARAMETER name:x index:0 type:kotlin.Int flags: + EXPRESSION_BODY + CONST Int type=kotlin.Int value=0 + PROPERTY name:x type:kotlin.Int visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public + EXPRESSION_BODY + GET_VAR 'value-parameter x: Int = ...' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test2) returnType:Int flags: + $this: VALUE_PARAMETER name: type:Test2 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_FIELD 'x: Int' type=kotlin.Int origin=null + receiver: GET_VAR 'this@Test2: Test2' type=Test2 origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + overridden: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + overridden: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS ANNOTATION_CLASS name:Test3 modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test3 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:Annotation modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> (x:Test1) returnType:Test3 flags: + VALUE_PARAMETER name:x index:0 type:Test1 flags: + PROPERTY name:x type:Test1 visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:x type:Test1 visibility:public + EXPRESSION_BODY + GET_VAR 'value-parameter x: Test1' type=Test1 origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test3) returnType:Test1 flags: + $this: VALUE_PARAMETER name: type:Test3 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Test1' + GET_FIELD 'x: Test1' type=Test1 origin=null + receiver: GET_VAR 'this@Test3: Test3' type=Test3 origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + overridden: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + overridden: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS ANNOTATION_CLASS name:Test4 modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test4 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:Annotation modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> (xs:kotlin.IntArray) returnType:Test4 flags: + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int flags:vararg + PROPERTY name:xs type:kotlin.IntArray visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:xs type:kotlin.IntArray visibility:public + EXPRESSION_BODY + GET_VAR 'value-parameter vararg xs: Int' type=kotlin.IntArray origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:Test4) returnType:IntArray flags: + $this: VALUE_PARAMETER name: type:Test4 flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): IntArray' + GET_FIELD 'xs: IntArray' type=kotlin.IntArray origin=null + receiver: GET_VAR 'this@Test4: Test4' type=Test4 origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + overridden: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + overridden: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: diff --git a/compiler/testData/ir/irText/classes/classes.txt b/compiler/testData/ir/irText/classes/classes.txt index 0a4defab34a..98772059f63 100644 --- a/compiler/testData/ir/irText/classes/classes.txt +++ b/compiler/testData/ir/irText/classes/classes.txt @@ -62,6 +62,7 @@ FILE fqName: fileName:/classes.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:TestAnnotationClass flags: superClasses: CLASS IR_EXTERNAL_DECLARATION_STUB INTERFACE name:Annotation modality:ABSTRACT visibility:public flags: + CONSTRUCTOR visibility:public <> () returnType:TestAnnotationClass flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: overridden: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index ad7d1b7f891..bb03bd5cc60 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -39,6 +39,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/classes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("annotationClasses.kt") + public void testAnnotationClasses() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/classes/annotationClasses.kt"); + doTest(fileName); + } + @TestMetadata("argumentReorderingInDelegatingConstructorCall.kt") public void testArgumentReorderingInDelegatingConstructorCall() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.kt");