Files
kotlin-fork/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/inference.fir.kt
T
Tianyu Geng 6a03f31e50 FIR: add UnsafeCall resolution diagnostics
Previously unsafe call is reported as part of InapplicableWrongReceiver.
This makes it difficult for the downstream checkers to report different
diagnostics.
2021-04-19 15:11:13 +03:00

34 lines
786 B
Kotlin
Vendored

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