From 9c0eb285e25aead0cd0d5d2417f7ebbb988d84de Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 30 Apr 2012 15:43:13 +0400 Subject: [PATCH] back end test for 'variable as function' call case --- compiler/testData/codegen/functions/invoke.kt | 22 +++++++++++++++++++ .../jet/codegen/FunctionGenTest.java | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 compiler/testData/codegen/functions/invoke.kt diff --git a/compiler/testData/codegen/functions/invoke.kt b/compiler/testData/codegen/functions/invoke.kt new file mode 100644 index 00000000000..4f85a25ef06 --- /dev/null +++ b/compiler/testData/codegen/functions/invoke.kt @@ -0,0 +1,22 @@ +package invoke + +fun test1(predicate: (Int) -> Int, i: Int) = predicate(i) + +fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i) + +class Method { + fun invoke(i: Int) = i +} + +fun test3(method: Method, i: Int) = method.invoke(i) + +//todo +//fun test4(method: Method, i: Int) = method(i) + +fun box() : String { + if (test1({ it }, 1) != 1) return "fail 1" + if (test2({ it }, 2) != 2) return "fail 2" + if (test3(Method(), 3) != 3) return "fail 3" + //if (test4(Method(), 4) != 4) return "fail 4" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java index 1d2fbac51cd..9b5b8062251 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java @@ -101,4 +101,8 @@ public class FunctionGenTest extends CodegenTestCase { public void testLocalFunction () throws InvocationTargetException, IllegalAccessException { blackBoxFile("functions/localFunction.kt"); } + + public void testInvoke() { + blackBoxFile("functions/invoke.kt"); + } }