Local returns are only allowed with explicitly specified return types

This is a temporary limitation: otherwise type inference is having trouble to account for all the returned expressions.
 We will fix the inference and remove the limitation
This commit is contained in:
Andrey Breslav
2013-08-21 18:05:16 +04:00
parent d97506476f
commit 08625a6b2f
16 changed files with 52 additions and 23 deletions
@@ -1,7 +1,7 @@
fun test2(a: Int) {
(run @f{
if (a > 0) <!RETURN_NOT_ALLOWED!>return<!>
return@f 1
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
}): Int
}
@@ -1,5 +1,5 @@
fun test2() {
(run @f{return@f 1}): Int
(run @f{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,10 +1,10 @@
fun test() {
run(@f{return@f 1}): Int
run(@f{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>}): Int
}
fun test1() {
run(@{return@ 1}): Int
run(@{<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 1<!>}): Int
}
fun run<T>(f: () -> T): T { return f() }
@@ -4,7 +4,7 @@ fun test() {
if (a > 0) return "2"
return@local "3"
}
return@f 1
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
}): Int
}
@@ -1,9 +1,9 @@
fun test() {
(run @f{
run @ff {
return@ff "2"
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ff "2"<!>
}
return@f 1
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
}): Int
}
@@ -1,7 +1,7 @@
fun test(a: Int) {
run @f{
if (a > 0) return@f
else return@f 1
if (a > 0) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f<!>
else <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f 1<!>
}
}
@@ -1,7 +1,7 @@
fun test(a: Int) {
(run @f{
if (a > 0) return@f
else return@f Unit.VALUE
if (a > 0) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f<!>
else <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f Unit.VALUE<!>
}): Unit
}
@@ -0,0 +1,11 @@
fun test(a: Int) {
run @f{ (): Int ->
if (a > 0) return@f <!TYPE_MISMATCH!>""<!>
return@f 1
}
run { (): Int -> <!TYPE_MISMATCH!>""<!> }
run { (): Int -> 1 }
}
fun run<T>(f: () -> T): T { return f() }
@@ -5,7 +5,7 @@ trait C: A
fun test(a: C, b: B) {
(run @f{
if (a != b) return@f a
if (a != b) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@f a<!>
b
}): A
}