KT-6136 VerifyError on data class inheriting from trait
- coerce property values to proper data class component types - add tests #KT-6136 Fixed
This commit is contained in:
@@ -504,8 +504,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
for (PropertyDescriptor propertyDescriptor : properties) {
|
for (PropertyDescriptor propertyDescriptor : properties) {
|
||||||
Type asmType = typeMapper.mapType(propertyDescriptor);
|
Type asmType = typeMapper.mapType(propertyDescriptor);
|
||||||
|
|
||||||
genPropertyOnStack(iv, context, propertyDescriptor, 0);
|
Type thisPropertyType = genPropertyOnStack(iv, context, propertyDescriptor, 0);
|
||||||
genPropertyOnStack(iv, context, propertyDescriptor, 2);
|
StackValue.coerce(thisPropertyType, asmType, iv);
|
||||||
|
|
||||||
|
Type otherPropertyType = genPropertyOnStack(iv, context, propertyDescriptor, 2);
|
||||||
|
StackValue.coerce(otherPropertyType, asmType, iv);
|
||||||
|
|
||||||
if (asmType.getSort() == Type.ARRAY) {
|
if (asmType.getSort() == Type.ARRAY) {
|
||||||
Type elementType = correctElementType(asmType);
|
Type elementType = correctElementType(asmType);
|
||||||
@@ -565,10 +568,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.mul(Type.INT_TYPE);
|
iv.mul(Type.INT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
genPropertyOnStack(iv, context, propertyDescriptor, 0);
|
Type propertyType = genPropertyOnStack(iv, context, propertyDescriptor, 0);
|
||||||
|
Type asmType = typeMapper.mapType(propertyDescriptor);
|
||||||
|
StackValue.coerce(propertyType, asmType, iv);
|
||||||
|
|
||||||
Label ifNull = null;
|
Label ifNull = null;
|
||||||
Type asmType = typeMapper.mapType(propertyDescriptor);
|
|
||||||
if (!isPrimitive(asmType)) {
|
if (!isPrimitive(asmType)) {
|
||||||
ifNull = new Label();
|
ifNull = new Label();
|
||||||
iv.dup();
|
iv.dup();
|
||||||
@@ -688,7 +692,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, descriptorToDeclaration(parameter));
|
bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, descriptorToDeclaration(parameter));
|
||||||
assert property != null : "Property descriptor is not found for primary constructor parameter: " + parameter;
|
assert property != null : "Property descriptor is not found for primary constructor parameter: " + parameter;
|
||||||
|
|
||||||
genPropertyOnStack(iv, context, property, 0);
|
Type propertyType = genPropertyOnStack(iv, context, property, 0);
|
||||||
|
StackValue.coerce(propertyType, componentType, iv);
|
||||||
}
|
}
|
||||||
iv.areturn(componentType);
|
iv.areturn(componentType);
|
||||||
}
|
}
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
trait Id<T> {
|
||||||
|
val id: T
|
||||||
|
}
|
||||||
|
|
||||||
|
open data class Actor (
|
||||||
|
override val id: Int,
|
||||||
|
val firstName: String,
|
||||||
|
val lastName: String
|
||||||
|
) : Id<Int>
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a1 = Actor(1, "Jeff", "Bridges")
|
||||||
|
|
||||||
|
val a1c = a1.copy()
|
||||||
|
if (a1c.id != a1.id) return "Failed: a1.copy().id==${a1c.id}"
|
||||||
|
|
||||||
|
val a2 = Actor(2, "Jeff", "Bridges")
|
||||||
|
if (a2 == a1) return "Failed: a2==a1"
|
||||||
|
|
||||||
|
// Assume that our hashCode is good enough for this test :)
|
||||||
|
if (a2.hashCode() == a1.hashCode()) return "Failed: a2.hashCode()==a1.hashCode()"
|
||||||
|
|
||||||
|
a1.toString()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
interface Id<T> {
|
||||||
|
val id: T
|
||||||
|
}
|
||||||
|
|
||||||
|
open data class Actor (
|
||||||
|
id: Int,
|
||||||
|
val firstName: String,
|
||||||
|
val lastName: String
|
||||||
|
) : Id<Int> {
|
||||||
|
override val id: Int = id
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a1 = Actor(1, "Jeff", "Bridges")
|
||||||
|
val a1copy = a1.copy(id = a1.id)
|
||||||
|
|
||||||
|
if (a1copy.id != a1.id) return "Failed: a1copy.id==${a1copy.id}"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+12
@@ -1402,6 +1402,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt6136.kt")
|
||||||
|
public void testKt6136() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6136.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt6136_2.kt")
|
||||||
|
public void testKt6136_2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6136_2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6816.kt")
|
@TestMetadata("kt6816.kt")
|
||||||
public void testKt6816() throws Exception {
|
public void testKt6816() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6816.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6816.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user