JVM: correctly merge typed null values

1. merge(null of type A, null of type B) = null of unknown type;
2. merge(null of type A, something of type B) = merge(unknown null, B).

^KT-52311 Fixed
This commit is contained in:
pyos
2022-05-10 15:29:51 +02:00
committed by teamcity
parent dcdd1cd14e
commit 513ef575ce
11 changed files with 160 additions and 2 deletions
@@ -0,0 +1,29 @@
// WITH_STDLIB
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun someCondition() = true
suspend fun suspendHere() = suspendCoroutineUninterceptedOrReturn {
it.resume(Unit)
COROUTINE_SUSPENDED
}
fun expectString(x: String?) = x!!
suspend fun foo(): String {
var x: String? = null
if (someCondition()) {
x = "OK"
}
suspendHere()
return expectString(x)
}
fun box(): String {
var result = "fail"
suspend { result = foo() }.startCoroutine(EmptyContinuation)
return result
}
@@ -0,0 +1,29 @@
// WITH_STDLIB
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun someCondition() = false
suspend fun suspendHere() = suspendCoroutineUninterceptedOrReturn {
it.resume(Unit)
COROUTINE_SUSPENDED
}
fun expectString(x: String?) = x!!
suspend fun foo(): String {
var x: String? = "OK"
if (someCondition()) {
x = null as String?
}
suspendHere()
return expectString(x)
}
fun box(): String {
var result = "fail"
suspend { result = foo() }.startCoroutine(EmptyContinuation)
return result
}