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:
@@ -6,10 +6,10 @@ fun unitEmptyReturn() : Unit {return}
|
||||
fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>}
|
||||
fun unitUnitReturn() : Unit {return Unit.VALUE}
|
||||
fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return<!>}
|
||||
fun test2() : Any = @a {return@a 1}
|
||||
fun test2() : Any = @a {<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@a 1<!>}
|
||||
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
|
||||
fun test4(): ()-> Unit = { <!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return@test4<!> }
|
||||
fun test5(): Any = @{ return@ }
|
||||
fun test5(): Any = @{ <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@<!> }
|
||||
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return 1<!>}
|
||||
|
||||
fun bbb() {
|
||||
|
||||
+1
-1
@@ -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
-1
@@ -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() }
|
||||
+2
-2
@@ -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() }
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -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() }
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package kt411
|
||||
fun f() {
|
||||
invoker(
|
||||
@{
|
||||
return@ 11 // expects Function, but should expect Int
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 11<!> // expects Function, but should expect Int
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ fun t1() {
|
||||
fun t2() : String {
|
||||
val <!UNUSED_VARIABLE!>g<!> : ()-> Int = @{
|
||||
if (true) {
|
||||
return@ 1
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 1<!>
|
||||
}
|
||||
<!RETURN_NOT_ALLOWED!>return "s"<!>
|
||||
}
|
||||
@@ -37,7 +37,7 @@ fun t3() : String {
|
||||
else {
|
||||
<!RETURN_NOT_ALLOWED!>return <!ERROR_COMPILE_TIME_VALUE!>2<!><!>
|
||||
}
|
||||
return@ 0
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@ 0<!>
|
||||
}
|
||||
)
|
||||
invoker(
|
||||
@@ -55,7 +55,7 @@ fun t3() : String {
|
||||
|
||||
fun t4() : Int {
|
||||
val <!UNUSED_VARIABLE!>h<!> : ()-> String = @l{
|
||||
return@l "a"
|
||||
<!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return@l "a"<!>
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>g<!> : ()-> String = @{ () : String ->
|
||||
return@ "a"
|
||||
@@ -66,4 +66,4 @@ fun t4() : Int {
|
||||
}
|
||||
|
||||
return 12
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user