[FIR] Infer type of elvis from lhs if rhs is Nothing

^KT-50875 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-01-21 17:42:14 +03:00
parent 83ff0946fe
commit d1fb8338ef
8 changed files with 73 additions and 4 deletions
@@ -0,0 +1,23 @@
// ISSUE: KT-50875
interface A {
fun foo()
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <K> checkNotNull(x: K?, y: K): @kotlin.internal.Exact K {
return x ?: y
}
fun test_1(any: Any, a: A, nullableA: A?) {
var x = any // x has type Any
x = checkNotNull(nullableA, a) // inferred to Any
x.<!UNRESOLVED_REFERENCE!>foo<!>() // no smartcast
x = nullableA ?: a // inferred to Any
x.<!UNRESOLVED_REFERENCE!>foo<!>() // no smartcast
x = nullableA ?: return // inferred to Any, but has A type
x.foo() // smartcast
}