diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt index 3bf23a02df9..4ac5f61d82c 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt @@ -232,7 +232,9 @@ class BodyGenerator( // If we are here, we didn't find a superclass entry in super types. // Thus, super class should be Any. val superClass = classDescriptor.getSuperClassOrAny() - assert(KotlinBuiltIns.isAny(superClass)) { "$classDescriptor: Super class should be any: $superClass" } + assert(KotlinBuiltIns.isAny(superClass)) { + "$classDescriptor: Super class should be any: $superClass" + } generateAnySuperConstructorCall(irBlockBody, ktClassOrObject) } } 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 ba32d943ef2..bf91a4e2072 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 @@ -196,7 +196,10 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktClassOrObject: KtClassOrObject ): IrConstructor = declareConstructor(ktClassOrObject, ktClassOrObject.primaryConstructor ?: ktClassOrObject, primaryConstructorDescriptor) { - generatePrimaryConstructorBody(ktClassOrObject) + if (primaryConstructorDescriptor.isExpect) + null + else + generatePrimaryConstructorBody(ktClassOrObject) } fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor): IrConstructor = @@ -215,7 +218,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktConstructorElement: KtElement, ktParametersElement: KtElement, constructorDescriptor: ClassConstructorDescriptor, - generateBody: BodyGenerator.() -> IrBody + generateBody: BodyGenerator.() -> IrBody? ): IrConstructor = context.symbolTable.declareConstructor( ktConstructorElement.startOffset, ktConstructorElement.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt index a115a2acac3..b7cc1b9f677 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt @@ -62,7 +62,7 @@ class IrConstructorImpl( endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassConstructorDescriptor, - body: IrBody + body: IrBody? ) : this(startOffset, endOffset, origin, descriptor) { this.body = body } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt index 9d4361d681b..218fd601948 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt @@ -121,7 +121,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), mapConstructorDeclaration(declaration.descriptor), - declaration.body!!.transform() + declaration.body?.transform() ).transformParameters(declaration) protected fun T.transformTypeParameters( diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.kt b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.kt new file mode 100644 index 00000000000..fa1fdba455d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +MultiPlatformProjects + +expect abstract class A protected constructor() { + abstract fun foo() +} + +expect open class B(i: Int): A { + override fun foo() + open fun bar(s: String) +} + +actual abstract class A protected actual constructor() { + actual abstract fun foo() +} + +actual open class B actual constructor(i: Int): A() { + actual override fun foo() {} + actual open fun bar(s: String) {} +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.txt new file mode 100644 index 00000000000..95bb7cb285c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.txt @@ -0,0 +1,65 @@ +FILE fqName: fileName:/expectClassInherited.kt + CLASS CLASS name:A modality:ABSTRACT visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:A flags: + CONSTRUCTOR visibility:protected <> () returnType:A flags: + FUN name:foo visibility:public modality:ABSTRACT <> ($this:A) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:A flags: + 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: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:B modality:OPEN visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:B flags: + CONSTRUCTOR visibility:public <> (i:kotlin.Int) returnType:B flags: + VALUE_PARAMETER name:i index:0 type:kotlin.Int flags: + FUN name:foo visibility:public modality:OPEN <> ($this:B) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:B flags: + FUN name:bar visibility:public modality:OPEN <> ($this:B, s:kotlin.String) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:B flags: + VALUE_PARAMETER name:s index:0 type:kotlin.String flags: + 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: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:A modality:ABSTRACT visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:A flags: + CONSTRUCTOR visibility:protected <> () returnType:A flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='A' + FUN name:foo visibility:public modality:ABSTRACT <> ($this:A) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:A flags: + 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: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:B modality:OPEN visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:B flags: + CONSTRUCTOR visibility:public <> (i:kotlin.Int) returnType:B flags: + VALUE_PARAMETER name:i index:0 type:kotlin.Int flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor A()' + INSTANCE_INITIALIZER_CALL classDescriptor='B' + FUN name:foo visibility:public modality:OPEN <> ($this:B) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:B flags: + BLOCK_BODY + FUN name:bar visibility:public modality:OPEN <> ($this:B, s:kotlin.String) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:B flags: + VALUE_PARAMETER name:s index:0 type:kotlin.String flags: + BLOCK_BODY + 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: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + 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/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 144fd0679ad..41348e02e71 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -318,6 +318,21 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("compiler/testData/ir/irText/declarations/multiplatform") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Multiplatform extends AbstractIrTextTestCase { + public void testAllFilesPresentInMultiplatform() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/declarations/multiplatform"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("expectClassInherited.kt") + public void testExpectClassInherited() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/ir/irText/declarations/parameters") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)