KT-4982 this$0 is not initialized in the anonymous object

#KT-4982 Fixed
This commit is contained in:
Mikhael Bogdanov
2014-05-13 17:52:35 +04:00
parent 5d6b4d641b
commit 6fb0050575
5 changed files with 37 additions and 12 deletions
@@ -241,14 +241,14 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
mv.visitCode();
InstructionAdapter iv = new InstructionAdapter(mv);
iv.load(0, superClass);
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
int k = 1;
for (FieldInfo fieldInfo : args) {
k = AsmUtil.genAssignInstanceFieldFromParam(fieldInfo, k, iv);
}
iv.load(0, superClass);
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
iv.visitInsn(RETURN);
FunctionCodegen.endVisit(iv, "constructor", fun);
@@ -1156,6 +1156,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
InstructionAdapter iv = codegen.v;
if (closure != null) {
List<FieldInfo> argsFromClosure = ClosureCodegen.calculateConstructorParameters(typeMapper, closure, classAsmType);
int k = 1;
for (FieldInfo info : argsFromClosure) {
k = AsmUtil.genAssignInstanceFieldFromParam(info, k, iv);
}
}
if (superCall == null) {
genSimpleSuperCall(iv);
}
@@ -1166,14 +1174,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor);
}
if (closure != null) {
List<FieldInfo> argsFromClosure = ClosureCodegen.calculateConstructorParameters(typeMapper, closure, classAsmType);
int k = 1;
for (FieldInfo info : argsFromClosure) {
k = AsmUtil.genAssignInstanceFieldFromParam(info, k, iv);
}
}
int n = 0;
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
if (specifier == superCall) {
@@ -200,7 +200,6 @@ public class LambdaTransformer {
Map<Integer, LambdaInfo> indexToLambda = invocation.getLambdasToInline();
AbstractInsnNode cur = constructor.instructions.getFirst();
cur = cur.getNext(); //skip super call
List<LambdaInfo> capturedLambdas = new ArrayList<LambdaInfo>(); //captured var of inlined parameter
CapturedParamOwner owner = new CapturedParamOwner() {
@Override
@@ -0,0 +1,21 @@
abstract class WaitFor {
{
condition()
}
abstract fun condition() : Boolean;
}
fun box(): String {
val local = ""
var result = "fail"
val s = object: WaitFor() {
override fun condition(): Boolean {
result = "OK"
return result.length == 2
}
}
return result;
}
@@ -5142,6 +5142,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/super/kt4173_3.kt");
}
@TestMetadata("kt4982.kt")
public void testKt4982() throws Exception {
doTest("compiler/testData/codegen/box/super/kt4982.kt");
}
@TestMetadata("multipleSuperTraits.kt")
public void testMultipleSuperTraits() throws Exception {
doTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");