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
23 lines
430 B
Kotlin
Vendored
23 lines
430 B
Kotlin
Vendored
// WITH_REFLECT
|
|
// TARGET_BACKEND: JVM
|
|
|
|
fun <T : A> create(modelClass: Class<T>): T {
|
|
return if (modelClass.isAssignableFrom(B::class.java)) {
|
|
createViewModel()
|
|
} else {
|
|
throw Exception()
|
|
}
|
|
}
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
fun <T : A> createViewModel(): T {
|
|
return B() as T
|
|
}
|
|
|
|
open class A
|
|
class B : A()
|
|
|
|
fun box(): String {
|
|
val r = create(A::class.java)
|
|
return if (r is B) "OK" else "fail"
|
|
} |