KT-4119: Back-end (JVM) Internal error on code with local extensions

#KT-4119 Fixed
This commit is contained in:
Mikhael Bogdanov
2013-10-24 16:32:56 +04:00
parent 88a43fac5f
commit 604be8e0c1
4 changed files with 48 additions and 0 deletions
@@ -3021,10 +3021,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
private StackValue invokeOperation(JetOperationExpression expression, FunctionDescriptor op, CallableMethod callable) {
//TODO: similar logic exists in visitSimpleNameExpression - extract common logic
int functionLocalIndex = lookupLocalIndex(op);
if (functionLocalIndex >= 0) {
stackValueForLocal(op, functionLocalIndex).put(callable.getOwner(), v);
} else {
StackValue stackValue = context.lookupInContext(op, StackValue.local(0, OBJECT_TYPE), state, true);
if (stackValue != null) {
stackValue.put(callable.getOwner(), v);
}
}
ResolvedCall<? extends CallableDescriptor> resolvedCall =
bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
assert resolvedCall != null;
@@ -0,0 +1,12 @@
fun foo(f: (Int?) -> Int): Int {
return f(0)
}
fun box() : String {
fun Int?.plus(a:Int) : Int = a!! + 2
if (foo { it + 1} != 3) return "Fail 1"
if (foo { it plus 1} != 3) return "Fail 2"
return "OK"
}
@@ -0,0 +1,19 @@
fun box(): String {
fun Int.foo(a: Int): Int = a + 2
val s = object {
fun test(): Int {
return 1 foo 1
}
}
fun local(): Int {
return 1 foo 1
}
if (s.test() != 3) return "Fail"
if (local() != 3) return "Fail"
return "OK"
}
@@ -2506,6 +2506,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/functions/localFunctions/kt3978.kt");
}
@TestMetadata("kt4119.kt")
public void testKt4119() throws Exception {
doTest("compiler/testData/codegen/box/functions/localFunctions/kt4119.kt");
}
@TestMetadata("kt4119_2.kt")
public void testKt4119_2() throws Exception {
doTest("compiler/testData/codegen/box/functions/localFunctions/kt4119_2.kt");
}
@TestMetadata("localFunctionInConstructor.kt")
public void testLocalFunctionInConstructor() throws Exception {
doTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionInConstructor.kt");