Capturing this in constructor context
KT-4086 VerifyError creating anonymous object in constructor #KT-4086 Fixed
This commit is contained in:
@@ -1358,14 +1358,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void visitThisExpression(JetThisExpression expression) {
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference());
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
// @todo for now all our classes are inner so no need to lookup this. change it when we have real inners
|
||||
}
|
||||
else {
|
||||
assert descriptor instanceof CallableDescriptor;
|
||||
if (context.getCallableDescriptorWithReceiver() != descriptor) {
|
||||
context.lookupInContext(descriptor, null, state, true);
|
||||
}
|
||||
assert descriptor instanceof CallableDescriptor ||
|
||||
descriptor instanceof ClassDescriptor : "'This' reference target should be class or callable descriptor but was " + descriptor;
|
||||
if (context.getCallableDescriptorWithReceiver() != descriptor) {
|
||||
context.lookupInContext(descriptor, null, state, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -338,7 +338,13 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
result = result == null || myOuter == null ? myOuter : StackValue.composed(result, myOuter);
|
||||
}
|
||||
|
||||
StackValue resultValue = parentContext != null ? parentContext.lookupInContext(d, result, state, ignoreNoOuter) : null;
|
||||
StackValue resultValue;
|
||||
if (myOuter != null && getEnclosingClass() == d) {
|
||||
resultValue = result;
|
||||
} else {
|
||||
resultValue = parentContext != null ? parentContext.lookupInContext(d, result, state, ignoreNoOuter) : null;
|
||||
}
|
||||
|
||||
if (myOuter != null && resultValue != null) {
|
||||
closure.setCaptureThis();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
trait N
|
||||
|
||||
open class Base(n: N)
|
||||
|
||||
class Derived : Base(object: N{}) {
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
Derived()
|
||||
return "OK"
|
||||
}
|
||||
@@ -3466,6 +3466,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/objects/kt3684.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4086.kt")
|
||||
public void testKt4086() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/kt4086.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt535.kt")
|
||||
public void testKt535() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/kt535.kt");
|
||||
|
||||
Reference in New Issue
Block a user