From aa99c29d8d0225e4e1ed19ecfde98e5a499e7906 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 21 Aug 2013 18:05:36 +0400 Subject: [PATCH] JVM backend test for local returns --- .../codegen/box/closures/localReturn.kt | 19 +++++++++++++++++++ .../BlackBoxCodegenTestGenerated.java | 5 +++++ 2 files changed, 24 insertions(+) create mode 100644 compiler/testData/codegen/box/closures/localReturn.kt diff --git a/compiler/testData/codegen/box/closures/localReturn.kt b/compiler/testData/codegen/box/closures/localReturn.kt new file mode 100644 index 00000000000..2cdd072774f --- /dev/null +++ b/compiler/testData/codegen/box/closures/localReturn.kt @@ -0,0 +1,19 @@ +fun box(): String { + val a = 1 + val explicitlyReturned = run1 @f{(): String -> + if (a > 0) + return@f "OK" + else "Fail 1" + } + if (explicitlyReturned != "OK") return explicitlyReturned + + val implicitlyReturned = run1 @f{(): String -> + if (a < 0) + return@f "Fail 2" + else "OK" + } + if (implicitlyReturned != "OK") return implicitlyReturned + return "OK" +} + +fun run1(f: () -> T): T { return f() } \ 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 5aeae6d89a8..f32e86f7732 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -1199,6 +1199,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/closures/localFunctionInInitializer.kt"); } + @TestMetadata("localReturn.kt") + public void testLocalReturn() throws Exception { + doTest("compiler/testData/codegen/box/closures/localReturn.kt"); + } + @TestMetadata("recursiveClosure.kt") public void testRecursiveClosure() throws Exception { doTest("compiler/testData/codegen/box/closures/recursiveClosure.kt");