Files
kotlin-fork/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.kt
T
Dmitry Savvinov 816d89e393 [NI] Improved testdata after changes in applicabilities
This commits introduces testdata changes, where NI behaviour strictly
improved, after several previous fixes.

For some tests, just WITH_NEW_INFERENCE directive was added. It
indicates, that some of previous commits first introduced error in that
test, and then some other commit fixed it (netting no overall testdata
change). It is preferrably to keep those annotations until we will
migrate to NI completely, to prevent unexpected regressions.
2017-12-07 12:49:56 +03:00

23 lines
701 B
Kotlin
Vendored

// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
//KT-2216 Nullability of a value determined in function parameter computation doesn't pass to code following
package kt2216
fun bar(y: Int, z: Int) = y + z
fun baz(a: Int, b: Int, c: Int, d: Int) = a + b + c + d
fun foo() {
val x: Int? = 0
bar(if (x != null) x else return, x)
x + 2
bar(x, x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
val y: Int? = 0
val z: Int? = 0
bar(<!NI;TYPE_MISMATCH!>if (y != null) y else <!TYPE_MISMATCH!>z<!><!>, <!TYPE_MISMATCH!>y<!>)
y <!UNSAFE_OPERATOR_CALL!>+<!> 2
baz(<!TYPE_MISMATCH!>y<!>, <!TYPE_MISMATCH!>y<!>, if (y == null) return else y, y)
baz(y, z!!, z, y)
}