Skip to content

Commit 2b21280

Browse files
committed
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
1 parent 8761ef6 commit 2b21280

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@ private JvmMethodGenericSignature mapSignature(@NotNull FunctionDescriptor f, @N
10271027
}
10281028
}
10291029

1030+
if (f instanceof TypeAliasConstructorDescriptor) {
1031+
return mapSignature(((TypeAliasConstructorDescriptor) f).getUnderlyingConstructorDescriptor(), kind, skipGenericSignature);
1032+
}
1033+
10301034
if (CoroutineCodegenUtilKt.isSuspendFunctionNotSuspensionView(f)) {
10311035
return mapSignature(CoroutineCodegenUtilKt.getOrCreateJvmSuspendFunctionView(f), kind, skipGenericSignature);
10321036
}
@@ -1048,9 +1052,6 @@ public JvmMethodGenericSignature mapSignatureWithCustomParameters(
10481052
if (f instanceof FunctionImportedFromObject) {
10491053
return mapSignature(((FunctionImportedFromObject) f).getCallableFromObject(), kind, skipGenericSignature);
10501054
}
1051-
else if (f instanceof TypeAliasConstructorDescriptor) {
1052-
return mapSignatureWithCustomParameters(((TypeAliasConstructorDescriptor) f).getUnderlyingConstructorDescriptor(), kind, valueParameters, skipGenericSignature);
1053-
}
10541055

10551056
checkOwnerCompatibility(f);
10561057

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
open class LockFreeLinkedListNode(val s: String)
2+
private class SendBuffered(s: String) : LockFreeLinkedListNode(s)
3+
open class AddLastDesc2<out T : LockFreeLinkedListNode>(val node: T)
4+
typealias AddLastDesc<T> = AddLastDesc2<T>
5+
6+
fun describeSendBuffered(): AddLastDesc<*> {
7+
return object : AddLastDesc<SendBuffered>(SendBuffered("OK")) {}
8+
}
9+
10+
fun box() = describeSendBuffered().node.s
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@kotlin.Metadata
2+
public class AddLastDesc2 {
3+
private final @org.jetbrains.annotations.NotNull field node: LockFreeLinkedListNode
4+
public method <init>(@org.jetbrains.annotations.NotNull p0: LockFreeLinkedListNode): void
5+
public final @org.jetbrains.annotations.NotNull method getNode(): LockFreeLinkedListNode
6+
}
7+
8+
@kotlin.Metadata
9+
public class LockFreeLinkedListNode {
10+
private final @org.jetbrains.annotations.NotNull field s: java.lang.String
11+
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
12+
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
13+
}
14+
15+
@kotlin.Metadata
16+
public final class ObjectLiteralConstructorKt {
17+
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
18+
public final static @org.jetbrains.annotations.NotNull method describeSendBuffered(): AddLastDesc2
19+
}
20+
21+
@kotlin.Metadata
22+
final class SendBuffered {
23+
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
24+
}

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
@@ -17699,6 +17699,12 @@ public void testKt15109() throws Exception {
1769917699
doTest(fileName);
1770017700
}
1770117701

17702+
@TestMetadata("objectLiteralConstructor.kt")
17703+
public void testObjectLiteralConstructor() throws Exception {
17704+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt");
17705+
doTest(fileName);
17706+
}
17707+
1770217708
@TestMetadata("simple.kt")
1770317709
public void testSimple() throws Exception {
1770417710
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
@@ -17699,6 +17699,12 @@ public void testKt15109() throws Exception {
1769917699
doTest(fileName);
1770017700
}
1770117701

17702+
@TestMetadata("objectLiteralConstructor.kt")
17703+
public void testObjectLiteralConstructor() throws Exception {
17704+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt");
17705+
doTest(fileName);
17706+
}
17707+
1770217708
@TestMetadata("simple.kt")
1770317709
public void testSimple() throws Exception {
1770417710
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
@@ -21904,6 +21904,12 @@ public void testKt15109() throws Exception {
2190421904
doTest(fileName);
2190521905
}
2190621906

21907+
@TestMetadata("objectLiteralConstructor.kt")
21908+
public void testObjectLiteralConstructor() throws Exception {
21909+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/objectLiteralConstructor.kt");
21910+
doTest(fileName);
21911+
}
21912+
2190721913
@TestMetadata("simple.kt")
2190821914
public void testSimple() throws Exception {
2190921915
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");

0 commit comments

Comments
 (0)