KT-4137: Verify error

#KT-4137 Fixed
This commit is contained in:
Mikhael Bogdanov
2013-10-25 16:24:52 +04:00
parent 6074667fd4
commit e3882e2dfb
3 changed files with 33 additions and 5 deletions
@@ -124,6 +124,10 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
}
public StackValue getOuterExpression(@Nullable StackValue prefix, boolean ignoreNoOuter) {
return getOuterExpression(prefix, ignoreNoOuter, true);
}
private StackValue getOuterExpression(@Nullable StackValue prefix, boolean ignoreNoOuter, boolean captureThis) {
if (outerExpression == null) {
if (ignoreNoOuter) {
return null;
@@ -132,8 +136,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
throw new UnsupportedOperationException();
}
}
closure.setCaptureThis();
if (captureThis) {
closure.setCaptureThis();
}
return prefix != null ? StackValue.composed(prefix, outerExpression) : outerExpression;
}
@@ -286,6 +291,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
public StackValue lookupInContext(DeclarationDescriptor d, @Nullable StackValue result, GenerationState state, boolean ignoreNoOuter) {
MutableClosure top = closure;
StackValue myOuter = null;
if (top != null) {
EnclosedValueDescriptor answer = closure.getCaptureVariables().get(d);
if (answer != null) {
@@ -306,11 +312,15 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
}
}
StackValue outer = getOuterExpression(null, ignoreNoOuter);
result = result == null || outer == null ? outer : StackValue.composed(result, outer);
myOuter = getOuterExpression(null, ignoreNoOuter, false);
result = result == null || myOuter == null ? myOuter : StackValue.composed(result, myOuter);
}
return parentContext != null ? parentContext.lookupInContext(d, result, state, ignoreNoOuter) : null;
StackValue resultValue = parentContext != null ? parentContext.lookupInContext(d, result, state, ignoreNoOuter) : null;
if (myOuter != null && resultValue != null) {
closure.setCaptureThis();
}
return resultValue;
}
@NotNull
@@ -0,0 +1,13 @@
open class A(val s: Int) {
}
fun Int.foo(s: Int): Int {
return this + s
}
open class B : A({ 1 foo 2} ())
fun box(): String {
return if (B().s == 3) "OK" else "Fail"
}
@@ -1262,6 +1262,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/closures/kt3905.kt");
}
@TestMetadata("kt4137.kt")
public void testKt4137() throws Exception {
doTest("compiler/testData/codegen/box/closures/kt4137.kt");
}
@TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception {
doTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");