69a7bf7f68
This fixes some cases where we infer some type variable inside one of the branches to Nothing instead of the expected type because Nothing appeared in some other branch. Specifically, we add an equality instead of a subtype constraint during completion of calls to synthetic functions for if/when, try and !!. We don't do it when the call contains a (possibly nested) elvis or is inside the RHS of an assignment. Otherwise, we would prevent some smart-casts. #KT-65882 Fixed
13 lines
250 B
Kotlin
Vendored
13 lines
250 B
Kotlin
Vendored
fun <T> Any?.unsafeCast(): T = this as T
|
|
|
|
fun <R> foo(returnType: String): R {
|
|
return when {
|
|
returnType == "Nothing" -> throw Exception()
|
|
else -> null.unsafeCast()
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
foo<String>("")
|
|
return "OK"
|
|
} |