Fix translation of copy() fun in data class

Fix translation of copy() function in data class which has secondary
constructor in JS BE. See KT-16717.
This commit is contained in:
Alexey Andreev
2017-03-20 15:15:12 +03:00
committed by Alexey Andreev
parent b46205f60b
commit 466540399c
6 changed files with 50 additions and 1 deletions
@@ -0,0 +1,9 @@
data class A(val o: String, val k: String) {
constructor() : this("O", "k")
}
fun box(): String {
val a = A().copy(k = "K")
return a.o + a.k
}
@@ -0,0 +1,21 @@
@kotlin.Metadata
public final class A {
private final @org.jetbrains.annotations.NotNull field k: java.lang.String
private final @org.jetbrains.annotations.NotNull field o: java.lang.String
public method <init>(): void
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: java.lang.String): void
public final @org.jetbrains.annotations.NotNull method component1(): java.lang.String
public final @org.jetbrains.annotations.NotNull method component2(): java.lang.String
public synthetic static method copy$default(p0: A, p1: java.lang.String, p2: java.lang.String, p3: int, p4: java.lang.Object): A
public final @org.jetbrains.annotations.NotNull method copy(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: java.lang.String): A
public method equals(p0: java.lang.Object): boolean
public final @org.jetbrains.annotations.NotNull method getK(): java.lang.String
public final @org.jetbrains.annotations.NotNull method getO(): java.lang.String
public method hashCode(): int
public method toString(): java.lang.String
}
@kotlin.Metadata
public final class WithSecondaryConstructorKt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@@ -5787,6 +5787,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withGenericParameter.kt");
doTest(fileName);
}
@TestMetadata("withSecondaryConstructor.kt")
public void testWithSecondaryConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withSecondaryConstructor.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/dataClasses/equals")
@@ -5787,6 +5787,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withGenericParameter.kt");
doTest(fileName);
}
@TestMetadata("withSecondaryConstructor.kt")
public void testWithSecondaryConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withSecondaryConstructor.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/dataClasses/equals")
@@ -6520,6 +6520,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withGenericParameter.kt");
doTest(fileName);
}
@TestMetadata("withSecondaryConstructor.kt")
public void testWithSecondaryConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/copy/withSecondaryConstructor.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/dataClasses/equals")
@@ -91,7 +91,8 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
}
ClassDescriptor classDescriptor = (ClassDescriptor) function.getContainingDeclaration();
ClassConstructorDescriptor constructor = classDescriptor.getConstructors().iterator().next();
ClassConstructorDescriptor constructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
assert constructor != null : "Data class should have primary constructor: " + classDescriptor;
JsExpression constructorRef = context.getInnerReference(constructor);