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:
@@ -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