2bafcddf7a
Namely, do not choose `Nothing?` result type when fixing a variable that has other constraints besides the ones that came from the relevant type parameter's upper bounds. See more details in KT-55691. In K1, the case from specialCallWithMaterializeAndExpectedType.kt was working (inferred to String?) just because the branches were analyzed independently with `String?` expected type. This change became necessary after the previous commit when we united inference subsystems for if/when branches (see motivation there). NB: For K1, the behavior is left the same, but the code was refactored a bit. ^KT-55691 Fixed ^KT-56448 Fixed
48 lines
1.1 KiB
Kotlin
Vendored
48 lines
1.1 KiB
Kotlin
Vendored
fun test_1(value: Any?): String? {
|
|
return { // BLOCK
|
|
val tmp0_safe_receiver: Any? = value
|
|
when {
|
|
EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null
|
|
else -> tmp0_safe_receiver.let<Any, Nothing>(block = local fun <anonymous>(it: Any): Nothing {
|
|
return "O"
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test_2(value: Any?): String? {
|
|
return run<String?>(block = local fun <anonymous>(): String? {
|
|
return { // BLOCK
|
|
val tmp1_safe_receiver: Any? = value
|
|
when {
|
|
EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null
|
|
else -> tmp1_safe_receiver.let<Any, Nothing>(block = local fun <anonymous>(it: Any): Nothing {
|
|
return "K"
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
fun box(): String {
|
|
var result: String = ""
|
|
result = result.plus(other = { // BLOCK
|
|
val <elvis>: String? = test_1(value = 1)
|
|
when {
|
|
EQEQ(arg0 = <elvis>, arg1 = null) -> return "fail 1"
|
|
else -> <elvis>
|
|
}
|
|
})
|
|
result = result.plus(other = { // BLOCK
|
|
val <elvis>: String? = test_2(value = 1)
|
|
when {
|
|
EQEQ(arg0 = <elvis>, arg1 = null) -> return "fail 2"
|
|
else -> <elvis>
|
|
}
|
|
})
|
|
return result
|
|
}
|