Support local returns in lambdas

This commit is contained in:
Andrey Breslav
2013-08-21 17:33:58 +04:00
parent 3ead1cea37
commit 4138ac4e36
11 changed files with 171 additions and 28 deletions
@@ -0,0 +1,8 @@
fun test2(a: Int) {
(run @f{
if (a > 0) <!RETURN_NOT_ALLOWED!>return<!>
return@f 1
}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,5 +1,5 @@
fun test2() {
run @f{return@f 1}
(run @f{return@f 1}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,10 +1,10 @@
fun test() {
run(@f{return@f 1})
run(@f{return@f 1}): Int
}
fun test1() {
run(@{return@ 1})
run(@{return@ 1}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -0,0 +1,11 @@
fun test() {
(run @f{
fun local(a: Int): String {
if (a > 0) return "2"
return@local "3"
}
return@f 1
}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -0,0 +1,10 @@
fun test() {
(run @f{
run @ff {
return@ff "2"
}
return@f 1
}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -0,0 +1,8 @@
fun test(a: Int) {
run @f{
if (a > 0) return@f
else return@f 1
}
}
fun run<T>(f: () -> T): T { return f() }
@@ -0,0 +1,8 @@
fun test(a: Int) {
(run @f{
if (a > 0) return@f
else return@f Unit.VALUE
}): Unit
}
fun run<T>(f: () -> T): T { return f() }
@@ -0,0 +1,13 @@
trait A
trait B: A
trait C: A
fun test(a: C, b: B) {
(run @f{
if (a != b) return@f a
b
}): A
}
fun run<T>(f: () -> T): T { return f() }