Control flow graph for safe calls corrected #KT-10913 Fixed

Also #KT-10186 Fixed
Also #KT-5198 Fixed
This commit is contained in:
Mikhail Glukhikh
2016-02-02 16:17:02 +03:00
committed by Mikhail Glukhikh
parent 5ae394fec0
commit a08b8f43b2
15 changed files with 660 additions and 2 deletions
@@ -0,0 +1,25 @@
// See also KT-5198 / KT-10186
inline fun doCall(f: () -> Unit) = f()
fun test1(nonLocal: String): String {
val localResult = doCall {
return nonLocal //unreachable
}
return "NON_LOCAL_FAILED $localResult" //unreachable
}
fun doSomething() {}
fun test2() {
fun f(x: Any?) = x
f(null?.let { return })
// false unreachable here
doSomething()
}
fun test3(x: Any?): Boolean =
x?.let {
return true
} ?: false
@@ -0,0 +1,7 @@
package
public inline fun doCall(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public fun doSomething(): kotlin.Unit
public fun test1(/*0*/ nonLocal: kotlin.String): kotlin.String
public fun test2(): kotlin.Unit
public fun test3(/*0*/ x: kotlin.Any?): kotlin.Boolean
@@ -0,0 +1,12 @@
// See KT-10913 Bogus unreachable code warning
fun fn() : String? = null
fun foo(): String {
val x = fn()?.let { throw Exception() } ?: "unreachable?"
return x
}
fun bar(): String {
val x = fn() ?: return ""
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>y<!> =<!> x<!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() } <!USELESS_ELVIS, UNREACHABLE_CODE!>?: "unreachable"<!>
<!UNREACHABLE_CODE!>return y<!>
}
@@ -0,0 +1,5 @@
package
public fun bar(): kotlin.String
public fun fn(): kotlin.String?
public fun foo(): kotlin.String