changed behavior of componentX/toString/hashCode and equals to work naturally with overriden properties

This commit is contained in:
Alex Tkachman
2012-09-18 18:08:16 +03:00
parent ae93018546
commit 7b066faa9f
3 changed files with 12 additions and 15 deletions
@@ -534,15 +534,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private Type genPropertyOnStack(InstructionAdapter iv, PropertyDescriptor propertyDescriptor, int index) { private Type genPropertyOnStack(InstructionAdapter iv, PropertyDescriptor propertyDescriptor, int index) {
iv.load(index, classAsmType); iv.load(index, classAsmType);
// todo: seems to be more correct - need to be changed in sync with 'componentX' generation and related tests final Method
// final Method method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
// method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
// iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor());
// iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor()); return method.getReturnType();
// final Type type = method.getReturnType();
Type type = typeMapper.mapType(propertyDescriptor);
iv.getfield(classAsmType.getInternalName(), propertyDescriptor.getName().getName(), type.getDescriptor());
return type;
} }
private void generateComponentFunctionsForDataClasses() { 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; assert returnType != null : "Return type of component function should not be null: " + function;
Type componentType = typeMapper.mapReturnType(returnType); Type componentType = typeMapper.mapReturnType(returnType);
final String desc = "()" + componentType.getDescriptor();
MethodVisitor mv = v.newMethod(myClass, MethodVisitor mv = v.newMethod(myClass,
FunctionCodegen.getMethodAsmFlags(function, OwnerKind.IMPLEMENTATION), FunctionCodegen.getMethodAsmFlags(function, OwnerKind.IMPLEMENTATION),
function.getName().getName(), function.getName().getName(),
"()" + componentType.getDescriptor(), desc,
null, null); null, null);
FunctionCodegen.genJetAnnotations(state, function, null, null, mv); FunctionCodegen.genJetAnnotations(state, function, null, null, mv);
@@ -575,7 +572,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
InstructionAdapter iv = new InstructionAdapter(mv); InstructionAdapter iv = new InstructionAdapter(mv);
if (!componentType.equals(Type.VOID_TYPE)) { if (!componentType.equals(Type.VOID_TYPE)) {
iv.load(0, classAsmType); 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); iv.areturn(componentType);
@@ -1,7 +1,7 @@
open data class A(open val x: String) open data class A(open val x: String)
class B : A("OK") { class B : A("Fail") {
override val x: String = "Fail" override val x: String = "OK"
} }
fun foo(a: A) = a.component1() fun foo(a: A) = a.component1()
@@ -1,7 +1,7 @@
open data class A(open val x: String) open data class A(open val x: String)
class B : A("OK") { class B : A("Fail") {
override val x: String = "Fail" override val x: String = "OK"
} }
fun foo(a: A) = a fun foo(a: A) = a