Files
kotlin-fork/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt
T
Denis.Zharkov 0d070f8ba9 K2: Fix processing inference lower bound NullableType <: T & Any
Previously, it was led to plainly adding NullableType <: T constraint
which silently led to successful call completion.
What is suggested is just marking such initial constraint
as unsuccessful.

In K1, the error was reported just via additional type checking
mechanism being run after call completion.

^KT-58665 Fixed
2023-06-07 09:42:55 +00:00

34 lines
760 B
Kotlin
Vendored

// !LANGUAGE: +DefinitelyNonNullableTypes
fun <T> toDefNotNull(s: T): T & Any = s!!
fun <K> removeQuestionMark(x: K?): K = x!!
fun Any.foo() {}
fun <E> expectNN(e: E & Any) {}
fun <F> main(x: F, y: F, z: F, w: F, m: F) {
val y1 = toDefNotNull(x) // K instead of K & Any
val y2: F & Any = toDefNotNull(x) // K instead of K & Any
val x1 = removeQuestionMark(x) // T or T & Any
val x2: F & Any = removeQuestionMark(x) // T or T & Any
val z1 = x!!
val z2: F & Any = y!!
val w1 = if (z != null) z else return
val w2: F & Any = if (w != null) w else return
y1.foo()
y2.foo()
x1.foo()
x2.foo()
z1.foo()
z2.foo()
w1.foo()
w2.foo()
expectNN(<!ARGUMENT_TYPE_MISMATCH!>m<!>)
expectNN(m!!)
}