From 596dc68ea4b84fd82d2b7e0ec66393238a5d6d39 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Tue, 1 Apr 2014 10:37:16 +0400 Subject: [PATCH] KT-4340: Jvm backend generates invalid synthetic accessor for private extension property --- .../codegen/ImplementationBodyCodegen.java | 10 ++++-- .../testData/codegen/box/properties/kt4340.kt | 36 +++++++++++++++++++ .../BlackBoxCodegenTestGenerated.java | 5 +++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/box/properties/kt4340.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index cd1ee8ab2ce..1b52edd0535 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -1024,9 +1024,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { InstructionAdapter iv = codegen.v; boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration()); StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR); - if (!forceField) { - iv.load(0, OBJECT_TYPE); + + Type[] argTypes = signature.getAsmMethod().getArgumentTypes(); + for (int i = 0, reg = 0; i < argTypes.length; i++) { + Type argType = argTypes[i]; + iv.load(reg, argType); + //noinspection AssignmentToForLoopParameter + reg += argType.getSize(); } + property.put(property.type, iv); iv.areturn(signature.getReturnType()); } diff --git a/compiler/testData/codegen/box/properties/kt4340.kt b/compiler/testData/codegen/box/properties/kt4340.kt new file mode 100644 index 00000000000..63a97eb0f44 --- /dev/null +++ b/compiler/testData/codegen/box/properties/kt4340.kt @@ -0,0 +1,36 @@ +class A { + + var result: Int = 0; + + private val Int.times3: Int + get() = this * 3 + + private var Int.times: Int + get() = this * 4 + set(s: Int) { + result = this * s + } + + fun test(p: Int):Int { + return { + p.times3 + }() + } + + fun test2(p: Int, s: Int):Int { + { + p.times = s + }() + return result + } +} + +fun box() : String { + var result = A().test(3); + if (result != 9) return "fail1: $result" + + result = A().test2(2, 4); + if (result != 8) return "fail2: $result" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index f702d7fc68a..d4d84906c89 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4689,6 +4689,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/properties/kt4252_2.kt"); } + @TestMetadata("kt4340.kt") + public void testKt4340() throws Exception { + doTest("compiler/testData/codegen/box/properties/kt4340.kt"); + } + @TestMetadata("kt4373.kt") public void testKt4373() throws Exception { doTest("compiler/testData/codegen/box/properties/kt4373.kt");