Don't generate primary constructor body for expect classes
This commit is contained in:
@@ -232,7 +232,9 @@ class BodyGenerator(
|
|||||||
// If we are here, we didn't find a superclass entry in super types.
|
// If we are here, we didn't find a superclass entry in super types.
|
||||||
// Thus, super class should be Any.
|
// Thus, super class should be Any.
|
||||||
val superClass = classDescriptor.getSuperClassOrAny()
|
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)
|
generateAnySuperConstructorCall(irBlockBody, ktClassOrObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -196,7 +196,10 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
ktClassOrObject: KtClassOrObject
|
ktClassOrObject: KtClassOrObject
|
||||||
): IrConstructor =
|
): IrConstructor =
|
||||||
declareConstructor(ktClassOrObject, ktClassOrObject.primaryConstructor ?: ktClassOrObject, primaryConstructorDescriptor) {
|
declareConstructor(ktClassOrObject, ktClassOrObject.primaryConstructor ?: ktClassOrObject, primaryConstructorDescriptor) {
|
||||||
generatePrimaryConstructorBody(ktClassOrObject)
|
if (primaryConstructorDescriptor.isExpect)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
generatePrimaryConstructorBody(ktClassOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor): IrConstructor =
|
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor): IrConstructor =
|
||||||
@@ -215,7 +218,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
ktConstructorElement: KtElement,
|
ktConstructorElement: KtElement,
|
||||||
ktParametersElement: KtElement,
|
ktParametersElement: KtElement,
|
||||||
constructorDescriptor: ClassConstructorDescriptor,
|
constructorDescriptor: ClassConstructorDescriptor,
|
||||||
generateBody: BodyGenerator.() -> IrBody
|
generateBody: BodyGenerator.() -> IrBody?
|
||||||
): IrConstructor =
|
): IrConstructor =
|
||||||
context.symbolTable.declareConstructor(
|
context.symbolTable.declareConstructor(
|
||||||
ktConstructorElement.startOffset, ktConstructorElement.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor
|
ktConstructorElement.startOffset, ktConstructorElement.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ class IrConstructorImpl(
|
|||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
origin: IrDeclarationOrigin,
|
origin: IrDeclarationOrigin,
|
||||||
descriptor: ClassConstructorDescriptor,
|
descriptor: ClassConstructorDescriptor,
|
||||||
body: IrBody
|
body: IrBody?
|
||||||
) : this(startOffset, endOffset, origin, descriptor) {
|
) : this(startOffset, endOffset, origin, descriptor) {
|
||||||
this.body = body
|
this.body = body
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapConstructorDeclaration(declaration.descriptor),
|
mapConstructorDeclaration(declaration.descriptor),
|
||||||
declaration.body!!.transform()
|
declaration.body?.transform()
|
||||||
).transformParameters(declaration)
|
).transformParameters(declaration)
|
||||||
|
|
||||||
protected fun <T : IrTypeParametersContainer> T.transformTypeParameters(
|
protected fun <T : IrTypeParametersContainer> T.transformTypeParameters(
|
||||||
|
|||||||
+19
@@ -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) {}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
FILE fqName:<root> fileName:/expectClassInherited.kt
|
||||||
|
CLASS CLASS name:A modality:ABSTRACT visibility:public flags:
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> 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:<this> 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:<this> 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:<this> type:kotlin.Any flags:
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
|
||||||
|
CLASS CLASS name:B modality:OPEN visibility:public flags:
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> 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:<this> type:B flags:
|
||||||
|
FUN name:bar visibility:public modality:OPEN <> ($this:B, s:kotlin.String) returnType:Unit flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> 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:<this> 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:<this> type:kotlin.Any flags:
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
|
||||||
|
CLASS CLASS name:A modality:ABSTRACT visibility:public flags:
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> 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:<this> 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:<this> 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:<this> type:kotlin.Any flags:
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
|
||||||
|
CLASS CLASS name:B modality:OPEN visibility:public flags:
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> 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:<this> type:B flags:
|
||||||
|
BLOCK_BODY
|
||||||
|
FUN name:bar visibility:public modality:OPEN <> ($this:B, s:kotlin.String) returnType:Unit flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> 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:<this> 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:<this> type:kotlin.Any flags:
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
|
||||||
@@ -318,6 +318,21 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("compiler/testData/ir/irText/declarations/parameters")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user