diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index d779ff5dae1..51b3ffac2d3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -3021,10 +3021,17 @@ public class ExpressionCodegen extends JetVisitor 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 resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference()); assert resolvedCall != null; diff --git a/compiler/testData/codegen/box/functions/localFunctions/kt4119.kt b/compiler/testData/codegen/box/functions/localFunctions/kt4119.kt new file mode 100644 index 00000000000..2231bb57f8b --- /dev/null +++ b/compiler/testData/codegen/box/functions/localFunctions/kt4119.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/localFunctions/kt4119_2.kt b/compiler/testData/codegen/box/functions/localFunctions/kt4119_2.kt new file mode 100644 index 00000000000..30fe4a286dd --- /dev/null +++ b/compiler/testData/codegen/box/functions/localFunctions/kt4119_2.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 6f03aefc53c..8bc94eb96c6 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -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");