Fix nested classes codegen bug
When constructing a closure, codegen in some cases incorrectly determined if it needed to store a reference from a nested class to the outer
This commit is contained in:
@@ -32,8 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_THIS_FIELD;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLASS_FOR_FUNCTION;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.FQN;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
|
||||
public abstract class CodegenContext {
|
||||
@@ -265,12 +264,12 @@ public abstract class CodegenContext {
|
||||
}
|
||||
|
||||
protected void initOuterExpression(JetTypeMapper typeMapper, ClassDescriptor classDescriptor) {
|
||||
final ClassDescriptor enclosingClass = getEnclosingClass();
|
||||
outerExpression = enclosingClass != null
|
||||
? StackValue
|
||||
.field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor),
|
||||
CAPTURED_THIS_FIELD,
|
||||
false)
|
||||
ClassDescriptor enclosingClass = getEnclosingClass();
|
||||
outerExpression = enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor)
|
||||
? StackValue.field(typeMapper.mapType(enclosingClass),
|
||||
CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor),
|
||||
CAPTURED_THIS_FIELD,
|
||||
false)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
fun foo(f: (Int) -> Int) = f(0)
|
||||
|
||||
class Outer {
|
||||
class Nested {
|
||||
val y = foo { a -> a }
|
||||
}
|
||||
|
||||
fun bar(): String {
|
||||
val a = Nested()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer().bar()
|
||||
@@ -38,6 +38,11 @@ public class InnerNestedGenTestGenerated extends AbstractCodegenTest {
|
||||
doTest("compiler/testData/codegen/innerNested/createNestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("createdNestedInOuterMember.kt")
|
||||
public void testCreatedNestedInOuterMember() throws Exception {
|
||||
doTest("compiler/testData/codegen/innerNested/createdNestedInOuterMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dataLocalVariable.kt")
|
||||
public void testDataLocalVariable() throws Exception {
|
||||
doTest("compiler/testData/codegen/innerNested/dataLocalVariable.kt");
|
||||
|
||||
Reference in New Issue
Block a user