[FIR] Add equality constraint from expected type for some synthetic function calls
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
This commit is contained in:
committed by
Space Team
parent
eaef7122f6
commit
69a7bf7f68
@@ -0,0 +1,13 @@
|
||||
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"
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
// WITH_REFLECT
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, JS_IR_ES6, NATIVE
|
||||
// FIR status: KotlinNothingValueException from create()
|
||||
|
||||
fun <T : A> create(modelClass: Class<T>): T {
|
||||
return if (modelClass.isAssignableFrom(B::class.java)) {
|
||||
|
||||
Reference in New Issue
Block a user