From f950ff4b8f052ef2a3d1db2994ded85f352d370e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 7 Mar 2017 16:47:30 +0300 Subject: [PATCH] '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" --- .../codegen/ImplementationBodyCodegen.java | 6 +++--- .../testData/codegen/box/typealias/kt15109.kt | 9 +++++++++ .../light-analysis/typealias/kt15109.txt | 18 ++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 ++++++ 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/typealias/kt15109.kt create mode 100644 compiler/testData/codegen/light-analysis/typealias/kt15109.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 6dde314b579..d3a95084bec 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -1207,9 +1207,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } else if (descriptor instanceof VariableDescriptor) { - if (descriptor.getContainingDeclaration() instanceof ConstructorDescriptor) { - ClassDescriptor classDescriptor = - (ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration(); + DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); + if (containingDeclaration instanceof ConstructorDescriptor) { + ClassDescriptor classDescriptor = ((ConstructorDescriptor) containingDeclaration).getConstructedClass(); if (classDescriptor == ImplementationBodyCodegen.this.descriptor) return; } lookupInContext(descriptor); diff --git a/compiler/testData/codegen/box/typealias/kt15109.kt b/compiler/testData/codegen/box/typealias/kt15109.kt new file mode 100644 index 00000000000..f6846176bf5 --- /dev/null +++ b/compiler/testData/codegen/box/typealias/kt15109.kt @@ -0,0 +1,9 @@ +open class A(private val s: String = "") { + fun foo() = s +} + +typealias B = A + +class C : B(s = "OK") + +fun box() = C().foo() diff --git a/compiler/testData/codegen/light-analysis/typealias/kt15109.txt b/compiler/testData/codegen/light-analysis/typealias/kt15109.txt new file mode 100644 index 00000000000..d8e99eccf22 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/typealias/kt15109.txt @@ -0,0 +1,18 @@ +@kotlin.Metadata +public class A { + private final field s: java.lang.String + public @synthetic.kotlin.jvm.GeneratedByJvmOverloads method (): void + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public synthetic method (p0: java.lang.String, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void + public final @org.jetbrains.annotations.NotNull method foo(): java.lang.String +} + +@kotlin.Metadata +public final class C { + public method (): void +} + +@kotlin.Metadata +public final class Kt15109Kt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 97fed2a00fb..40b4e0ba438 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17681,6 +17681,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt15109.kt") + public void testKt15109() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 84d4946de1c..fd4cacdd2da 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -17681,6 +17681,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt15109.kt") + public void testKt15109() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.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 9a438eca61d..542611661d3 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 @@ -22179,6 +22179,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt15109.kt") + public void testKt15109() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/kt15109.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");