K2: Avoid using Nothing? as inference result in the majority of cases
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
This commit is contained in:
committed by
Space Team
parent
f12a4e08cf
commit
2bafcddf7a
@@ -12,7 +12,7 @@ fun test_1(value: Any?): String? {
|
||||
}
|
||||
|
||||
fun test_2(value: Any?): String? {
|
||||
return run<Nothing?>(block = local fun <anonymous>(): Nothing? {
|
||||
return run<String?>(block = local fun <anonymous>(): String? {
|
||||
return { // BLOCK
|
||||
val tmp1_safe_receiver: Any? = value
|
||||
when {
|
||||
|
||||
Reference in New Issue
Block a user