Fix capturing outer this in some cases in JVM codegen

When property initializer of some inner entity (e.g. anonymous object) contains
a reference to some outer entity (say, a property of the outer class), we need
to make sure we called "lookupInContext" on this entity's owner class, so that
"setCaptureThis" was called on the appropriate closure

 #KT-4176 Fixed
This commit is contained in:
Alexander Udalov
2014-02-12 19:08:43 +04:00
parent 7bf26283b2
commit 35c7c4afd8
11 changed files with 201 additions and 21 deletions
@@ -1384,7 +1384,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
@TestMetadata("compiler/testData/codegen/box/closures")
@InnerTestClasses({Closures.ClosureInsideClosure.class})
@InnerTestClasses({Closures.CaptureOuterProperty.class, Closures.ClosureInsideClosure.class})
public static class Closures extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInClosures() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -1510,6 +1510,49 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/closures/simplestClosureAndBoxing.kt");
}
@TestMetadata("compiler/testData/codegen/box/closures/captureOuterProperty")
public static class CaptureOuterProperty extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInCaptureOuterProperty() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/closures/captureOuterProperty"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("captureFunctionInProperty.kt")
public void testCaptureFunctionInProperty() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/captureFunctionInProperty.kt");
}
@TestMetadata("inFunction.kt")
public void testInFunction() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/inFunction.kt");
}
@TestMetadata("inProperty.kt")
public void testInProperty() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/inProperty.kt");
}
@TestMetadata("inPropertyDeepObjectChain.kt")
public void testInPropertyDeepObjectChain() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyDeepObjectChain.kt");
}
@TestMetadata("inPropertyFromSuperClass.kt")
public void testInPropertyFromSuperClass() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperClass.kt");
}
@TestMetadata("inPropertyFromSuperSuperClass.kt")
public void testInPropertyFromSuperSuperClass() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperSuperClass.kt");
}
@TestMetadata("kt4176.kt")
public void testKt4176() throws Exception {
doTest("compiler/testData/codegen/box/closures/captureOuterProperty/kt4176.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/closures/closureInsideClosure")
public static class ClosureInsideClosure extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInClosureInsideClosure() throws Exception {
@@ -1551,6 +1594,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public static Test innerSuite() {
TestSuite suite = new TestSuite("Closures");
suite.addTestSuite(Closures.class);
suite.addTestSuite(CaptureOuterProperty.class);
suite.addTestSuite(ClosureInsideClosure.class);
return suite;
}
@@ -1018,6 +1018,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/kt864.kt");
}
@TestMetadata("objectCaptureOuterConstructorProperty.kt")
public void testObjectCaptureOuterConstructorProperty() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/objectCaptureOuterConstructorProperty.kt");
}
@TestMetadata("referenceToSelfInLocal.kt")
public void testReferenceToSelfInLocal() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/referenceToSelfInLocal.kt");