Skip to content

Commit f950ff4

Browse files
committed
'ConstructorDescriptor#getConstructedClass()' should be used to obtain a descriptor for constructed class
(it can be different from 'getContainingDeclaration()' in case of type alias constructor). KT-15109 Subclass from a type alias with named parameter in constructor will produce compiler exception KT-15192 Compiler crashes on certain companion objects: "Error generating constructors of class Companion with kind IMPLEMENTATION"
1 parent 9a2c9ed commit f950ff4

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,9 @@ else if (descriptor instanceof CallableMemberDescriptor) {
12071207
}
12081208
}
12091209
else if (descriptor instanceof VariableDescriptor) {
1210-
if (descriptor.getContainingDeclaration() instanceof ConstructorDescriptor) {
1211-
ClassDescriptor classDescriptor =
1212-
(ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
1210+
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
1211+
if (containingDeclaration instanceof ConstructorDescriptor) {
1212+
ClassDescriptor classDescriptor = ((ConstructorDescriptor) containingDeclaration).getConstructedClass();
12131213
if (classDescriptor == ImplementationBodyCodegen.this.descriptor) return;
12141214
}
12151215
lookupInContext(descriptor);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
open class A(private val s: String = "") {
2+
fun foo() = s
3+
}
4+
5+
typealias B = A
6+
7+
class C : B(s = "OK")
8+
9+
fun box() = C().foo()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@kotlin.Metadata
2+
public class A {
3+
private final field s: java.lang.String
4+
public @synthetic.kotlin.jvm.GeneratedByJvmOverloads method <init>(): void
5+
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
6+
public synthetic method <init>(p0: java.lang.String, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void
7+
public final @org.jetbrains.annotations.NotNull method foo(): java.lang.String
8+
}
9+
10+
@kotlin.Metadata
11+
public final class C {
12+
public method <init>(): void
13+
}
14+
15+
@kotlin.Metadata
16+
public final class Kt15109Kt {
17+
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
18+
}

compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17681,6 +17681,12 @@ public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
1768117681
doTest(fileName);
1768217682
}
1768317683

17684+
@TestMetadata("kt15109.kt")
17685+
public void testKt15109() throws Exception {
17686+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt");
17687+
doTest(fileName);
17688+
}
17689+
1768417690
@TestMetadata("simple.kt")
1768517691
public void testSimple() throws Exception {
1768617692
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");

compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17681,6 +17681,12 @@ public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
1768117681
doTest(fileName);
1768217682
}
1768317683

17684+
@TestMetadata("kt15109.kt")
17685+
public void testKt15109() throws Exception {
17686+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt");
17687+
doTest(fileName);
17688+
}
17689+
1768417690
@TestMetadata("simple.kt")
1768517691
public void testSimple() throws Exception {
1768617692
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");

js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22179,6 +22179,12 @@ public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
2217922179
doTest(fileName);
2218022180
}
2218122181

22182+
@TestMetadata("kt15109.kt")
22183+
public void testKt15109() throws Exception {
22184+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt");
22185+
doTest(fileName);
22186+
}
22187+
2218222188
@TestMetadata("simple.kt")
2218322189
public void testSimple() throws Exception {
2218422190
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");

0 commit comments

Comments
 (0)