KT-413 proper visibility of this$0

This commit is contained in:
Alex Tkachman
2012-02-24 08:26:27 +02:00
parent f89b0c3193
commit 80e728b6f6
4 changed files with 32 additions and 2 deletions
@@ -140,7 +140,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
final Method constructor = generateConstructor(funClass, fun);
if (captureThis) {
cv.newField(fun, 0, "this$0", enclosingType.getDescriptor(), null, null);
cv.newField(fun, ACC_FINAL, "this$0", enclosingType.getDescriptor(), null, null);
}
if(isConst()) {
@@ -593,7 +593,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
final Type type = typeMapper.mapType(outerDescriptor.getDefaultType(), OwnerKind.IMPLEMENTATION);
String interfaceDesc = type.getDescriptor();
final String fieldName = "this$0";
v.newField(myClass, ACC_PRIVATE | ACC_FINAL, fieldName, interfaceDesc, null, null);
v.newField(myClass, ACC_FINAL, fieldName, interfaceDesc, null, null);
iv.load(0, classType);
iv.load(frameMap.getOuterThisIndex(), type);
iv.putfield(classname, fieldName, interfaceDesc);
@@ -0,0 +1,26 @@
package t
trait I{
fun f()
}
class Test{
fun foo(){
val i : I = object : I {
override fun f() {
fun local(){
bar()
}
local()
}
}
i.f()
}
fun bar(){}
}
fun box() : String {
Test().foo()
return "OK"
}
@@ -86,6 +86,10 @@ public class FunctionGenTest extends CodegenTestCase {
blackBoxFile("regressions/kt873.kt");
}
public void testKt1413 () {
blackBoxFile("regressions/kt1413.kt");
}
public void testKt1199 () {
blackBoxFile("regressions/kt1199.kt");
}