From ba76e1467c5b102fed5092c3897244d74cc8707f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 9 Jun 2012 16:19:41 +0200 Subject: [PATCH] correct argument index for object that has outer this and closure arguments #KT-1737 Fixed --- .../codegen/ImplementationBodyCodegen.java | 5 ++-- .../testData/codegen/regressions/kt1737.kt | 13 +++++++++ .../jetbrains/jet/codegen/ObjectGenTest.java | 28 +++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt1737.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index f366741c4eb..f0aa0307ec0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -656,7 +656,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } final ClassDescriptor outerDescriptor = typeMapper.getClosureAnnotator().getEclosingClassDescriptor(descriptor); - if (typeMapper.hasThis0(descriptor) && outerDescriptor != null) { + final boolean hasOuterThis = typeMapper.hasThis0(descriptor) && outerDescriptor != null; + if (hasOuterThis) { final Type type = typeMapper.mapType(outerDescriptor.getDefaultType(), MapTypeMode.VALUE); String interfaceDesc = type.getDescriptor(); final String fieldName = "this$0"; @@ -667,7 +668,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } if (closure != null) { - int k = outerDescriptor != null && outerDescriptor.getKind() != ClassKind.OBJECT ? 2 : 1; + int k = hasOuterThis ? 2 : 1; if (closure.captureReceiver != null) { iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(1, closure.captureReceiver); diff --git a/compiler/testData/codegen/regressions/kt1737.kt b/compiler/testData/codegen/regressions/kt1737.kt new file mode 100644 index 00000000000..c5f7fb5dd4b --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1737.kt @@ -0,0 +1,13 @@ +fun box(): String { + return object { + fun foo(): String { + val f = {} + object : Runnable { + public override fun run() { + f() + } + } + return "OK" + } + }.foo() +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/ObjectGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ObjectGenTest.java index a051fa517e5..8c2061ae8d6 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ObjectGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ObjectGenTest.java @@ -29,54 +29,58 @@ public class ObjectGenTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS); } - public void testSimpleObject() throws Exception { + public void testSimpleObject() { blackBoxFile("objects/simpleObject.jet"); // System.out.println(generateToText()); } - public void testObjectLiteral() throws Exception { + public void testObjectLiteral() { blackBoxFile("objects/objectLiteral.jet"); // System.out.println(generateToText()); } - public void testObjectLiteralInClosure() throws Exception { + public void testObjectLiteralInClosure() { blackBoxFile("objects/objectLiteralInClosure.jet"); // System.out.println(generateToText()); } - public void testMethodOnObject() throws Exception { + public void testMethodOnObject() { blackBoxFile("objects/methodOnObject.jet"); } - public void testKt535() throws Exception { + public void testKt535() { blackBoxFile("regressions/kt535.jet"); } - public void testKt560() throws Exception { + public void testKt560() { blackBoxFile("regressions/kt560.jet"); } - public void testKt640() throws Exception { + public void testKt640() { blackBoxFile("regressions/kt640.jet"); } - public void testKt1136() throws Exception { + public void testKt1136() { blackBoxFile("regressions/kt1136.kt"); } - public void testKt1047() throws Exception { + public void testKt1047() { blackBoxFile("regressions/kt1047.kt"); } - public void testKt694() throws Exception { + public void testKt694() { blackBoxFile("regressions/kt694.kt"); } - public void testKt1186() throws Exception { + public void testKt1186() { blackBoxFile("regressions/kt1186.kt"); } - public void testKt1600() throws Exception { + public void testKt1600() { blackBoxFile("regressions/kt1600.kt"); } + + public void testKt1737() { + blackBoxFile("regressions/kt1737.kt"); + } }