From 2b21280ba993aa22790485db5b8a8be733c60609 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 1 Mar 2017 17:07:27 +0300 Subject: [PATCH] Unwrap underlying typealias constructor earlier The problem is very subtle (see the test): when generating a signature for an object literal we also were mapping its super-class (a type alias here). Although we did unwrap its underlying constructor to map it properly we did too late (after obtaining value parameters from the type alias constructor descriptor). Another problem is that TypeAliasConstructorDescriptor.getOriginal in the case does return itself, while it's expected to return unsubstituted version Note: everything works for common calls for such constructors because they mapped through mapCallableMethod which contains another custom unwrapping of type alias constructors #KT-16555 Fixed --- .../codegen/state/KotlinTypeMapper.java | 7 +++--- .../box/typealias/objectLiteralConstructor.kt | 10 ++++++++ .../typealias/objectLiteralConstructor.txt | 24 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 +++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt create mode 100644 compiler/testData/codegen/light-analysis/typealias/objectLiteralConstructor.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 1628f7fcb94..31187557e96 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -1027,6 +1027,10 @@ public class KotlinTypeMapper { } } + if (f instanceof TypeAliasConstructorDescriptor) { + return mapSignature(((TypeAliasConstructorDescriptor) f).getUnderlyingConstructorDescriptor(), kind, skipGenericSignature); + } + if (CoroutineCodegenUtilKt.isSuspendFunctionNotSuspensionView(f)) { return mapSignature(CoroutineCodegenUtilKt.getOrCreateJvmSuspendFunctionView(f), kind, skipGenericSignature); } @@ -1048,9 +1052,6 @@ public class KotlinTypeMapper { if (f instanceof FunctionImportedFromObject) { return mapSignature(((FunctionImportedFromObject) f).getCallableFromObject(), kind, skipGenericSignature); } - else if (f instanceof TypeAliasConstructorDescriptor) { - return mapSignatureWithCustomParameters(((TypeAliasConstructorDescriptor) f).getUnderlyingConstructorDescriptor(), kind, valueParameters, skipGenericSignature); - } checkOwnerCompatibility(f); diff --git a/compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt b/compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt new file mode 100644 index 00000000000..eab3abf7d1d --- /dev/null +++ b/compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt @@ -0,0 +1,10 @@ +open class LockFreeLinkedListNode(val s: String) +private class SendBuffered(s: String) : LockFreeLinkedListNode(s) +open class AddLastDesc2(val node: T) +typealias AddLastDesc = AddLastDesc2 + +fun describeSendBuffered(): AddLastDesc<*> { + return object : AddLastDesc(SendBuffered("OK")) {} +} + +fun box() = describeSendBuffered().node.s diff --git a/compiler/testData/codegen/light-analysis/typealias/objectLiteralConstructor.txt b/compiler/testData/codegen/light-analysis/typealias/objectLiteralConstructor.txt new file mode 100644 index 00000000000..f42fbb1f1b4 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/typealias/objectLiteralConstructor.txt @@ -0,0 +1,24 @@ +@kotlin.Metadata +public class AddLastDesc2 { + private final @org.jetbrains.annotations.NotNull field node: LockFreeLinkedListNode + public method (@org.jetbrains.annotations.NotNull p0: LockFreeLinkedListNode): void + public final @org.jetbrains.annotations.NotNull method getNode(): LockFreeLinkedListNode +} + +@kotlin.Metadata +public class LockFreeLinkedListNode { + private final @org.jetbrains.annotations.NotNull field s: java.lang.String + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String +} + +@kotlin.Metadata +public final class ObjectLiteralConstructorKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method describeSendBuffered(): AddLastDesc2 +} + +@kotlin.Metadata +final class SendBuffered { + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void +} 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 53ed1cc4e92..8a4770dca4f 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 @@ -17699,6 +17699,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("objectLiteralConstructor.kt") + public void testObjectLiteralConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.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 a37bc916147..6031d2b43c3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -17699,6 +17699,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("objectLiteralConstructor.kt") + public void testObjectLiteralConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.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 6e52997d961..009ddf14154 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 @@ -21904,6 +21904,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("objectLiteralConstructor.kt") + public void testObjectLiteralConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");