correct argument index for object that has outer this and closure arguments

#KT-1737 Fixed
This commit is contained in:
Dmitry Jemerov
2012-06-09 16:19:41 +02:00
parent a23f0018a5
commit ba76e1467c
3 changed files with 32 additions and 14 deletions
@@ -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);
@@ -0,0 +1,13 @@
fun box(): String {
return object {
fun foo(): String {
val f = {}
object : Runnable {
public override fun run() {
f()
}
}
return "OK"
}
}.foo()
}
@@ -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");
}
}