Files
kotlin-fork/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt
T
Mikhail Zarechenskiy c458393e2f [NI] Do not avoid trivial constraints if they aren't from upper bounds
Since we skipped trivial constraint with `Any?` from parameter type of
 function `equals`, the compiler thought that there is no proper
 constraints (upper bounds do not matter here) and marked resolved
 call as a failed one, then diagnostic about missing equals was added

 Also, tune `TrivialConstraintTypeInferenceOracle` for `Any?`-like
 constraints

 #KT-30724 Fixed
2019-04-02 12:21:14 +03:00

40 lines
1.0 KiB
Kotlin
Vendored

// !WITH_NEW_INFERENCE
//KT-2164 !! does not propagate nullability information
package kt2164
fun foo(x: Int): Int = x + 1
fun main() {
val x: Int? = null
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
} else {
foo(<!DEBUG_INFO_CONSTANT, TYPE_MISMATCH!>x<!>)
<!UNREACHABLE_CODE!>foo(<!><!ALWAYS_NULL!>x<!>!!<!UNREACHABLE_CODE!>)<!>
<!UNREACHABLE_CODE!>foo(<!DEBUG_INFO_SMARTCAST!>x<!>)<!>
}
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null
y!!
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
foo(<!DEBUG_INFO_SMARTCAST!>y<!>)
foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}