KT-799 Allow 'return' expressions in conditionals assigned to variables
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package kt799
|
||||
|
||||
fun foo(b: Boolean) : String {
|
||||
val a = if (b) true else return "false"
|
||||
return "$a"
|
||||
}
|
||||
|
||||
fun box() = if (foo(true) == "true" && foo(false) == "false") "OK" else "fail"
|
||||
@@ -7,10 +7,10 @@ fun unitEmpty() : Unit {}
|
||||
fun unitEmptyReturn() : Unit {return}
|
||||
fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>}
|
||||
fun unitUnitReturn() : Unit {return #()}
|
||||
fun test1() : Any = {<!RETURN_TYPE_MISMATCH, RETURN_NOT_ALLOWED!>return<!>}
|
||||
fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return<!>}
|
||||
fun test2() : Any = @a {return@a 1}
|
||||
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
|
||||
fun test4(): ()-> Unit = { <!RETURN_TYPE_MISMATCH, RETURN_NOT_ALLOWED!>return@test4<!> }
|
||||
fun test4(): ()-> Unit = { <!RETURN_NOT_ALLOWED, RETURN_TYPE_MISMATCH!>return@test4<!> }
|
||||
fun test5(): Any = @{ return@ }
|
||||
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return 1<!>}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ class A {
|
||||
<!RETURN_NOT_ALLOWED!>return@outer<!>
|
||||
}
|
||||
if (1 < 2)
|
||||
<!RETURN_NOT_ALLOWED!>return@A<!>
|
||||
<!NOT_A_RETURN_LABEL!>return@A<!>
|
||||
else if (2 < 3)
|
||||
<!RETURN_NOT_ALLOWED!>return<!UNRESOLVED_REFERENCE!>@inner<!><!>
|
||||
return<!UNRESOLVED_REFERENCE!>@inner<!>
|
||||
return@outer
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//KT-799 Allow 'return' expressions in conditionals assigned to variables
|
||||
|
||||
package kt799
|
||||
|
||||
fun test() {
|
||||
val <!UNUSED_VARIABLE!>a<!> : Int = if (true) 6 else return // should be allowed
|
||||
|
||||
val <!UNUSED_VARIABLE!>b<!> = if (true) 6 else return // should be allowed
|
||||
|
||||
doSmth(if (true) 3 else return)
|
||||
|
||||
doSmth(if (true) 3 else return, <!TOO_MANY_ARGUMENTS!>1<!>)
|
||||
}
|
||||
|
||||
val a : Nothing = <!RETURN_NOT_ALLOWED!>return 1<!>
|
||||
|
||||
val b = <!RETURN_NOT_ALLOWED!>return 1<!>
|
||||
|
||||
val c = doSmth(if (true) 3 else <!RETURN_NOT_ALLOWED!>return<!>)
|
||||
|
||||
|
||||
fun f(<!UNUSED_PARAMETER!>mi<!>: Int = if (true) 0 else <!RETURN_NOT_ALLOWED!>return<!>) {}
|
||||
|
||||
fun doSmth(<!UNUSED_PARAMETER!>i<!>: Int) {
|
||||
}
|
||||
Reference in New Issue
Block a user