From 7b066faa9f261782cbeabdd19a8e485ff780ad6b Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Tue, 18 Sep 2012 18:08:16 +0300 Subject: [PATCH] changed behavior of componentX/toString/hashCode and equals to work naturally with overriden properties --- .../codegen/ImplementationBodyCodegen.java | 19 ++++++++----------- .../codegen/dataClasses/overriddenProperty.kt | 4 ++-- .../tostring/overriddenProperty.kt | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index b30c1a77b02..f5d2deed38c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -534,15 +534,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { private Type genPropertyOnStack(InstructionAdapter iv, PropertyDescriptor propertyDescriptor, int index) { iv.load(index, classAsmType); - // todo: seems to be more correct - need to be changed in sync with 'componentX' generation and related tests - // final Method - // method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); - // - // iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor()); - // final Type type = method.getReturnType(); - Type type = typeMapper.mapType(propertyDescriptor); - iv.getfield(classAsmType.getInternalName(), propertyDescriptor.getName().getName(), type.getDescriptor()); - return type; + final Method + method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); + + iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor()); + return method.getReturnType(); } private void generateComponentFunctionsForDataClasses() { @@ -563,10 +559,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { assert returnType != null : "Return type of component function should not be null: " + function; Type componentType = typeMapper.mapReturnType(returnType); + final String desc = "()" + componentType.getDescriptor(); MethodVisitor mv = v.newMethod(myClass, FunctionCodegen.getMethodAsmFlags(function, OwnerKind.IMPLEMENTATION), function.getName().getName(), - "()" + componentType.getDescriptor(), + desc, null, null); FunctionCodegen.genJetAnnotations(state, function, null, null, mv); @@ -575,7 +572,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { InstructionAdapter iv = new InstructionAdapter(mv); if (!componentType.equals(Type.VOID_TYPE)) { iv.load(0, classAsmType); - iv.getfield(classAsmType.getInternalName(), parameter.getName().getName(), componentType.getDescriptor()); + iv.invokevirtual(classAsmType.getInternalName(), PropertyCodegen.getterName(parameter.getName()), desc); } iv.areturn(componentType); diff --git a/compiler/testData/codegen/dataClasses/overriddenProperty.kt b/compiler/testData/codegen/dataClasses/overriddenProperty.kt index 113a2b176c1..50f27979b39 100644 --- a/compiler/testData/codegen/dataClasses/overriddenProperty.kt +++ b/compiler/testData/codegen/dataClasses/overriddenProperty.kt @@ -1,7 +1,7 @@ open data class A(open val x: String) -class B : A("OK") { - override val x: String = "Fail" +class B : A("Fail") { + override val x: String = "OK" } fun foo(a: A) = a.component1() diff --git a/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt b/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt index cac12ae4177..ab0b1856eec 100644 --- a/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt +++ b/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt @@ -1,7 +1,7 @@ open data class A(open val x: String) -class B : A("OK") { - override val x: String = "Fail" +class B : A("Fail") { + override val x: String = "OK" } fun foo(a: A) = a