Files
Dmitriy Novozhilov 26b9948e5f [FE 1.0] Make type of safe call always nullable
^KT-46860 In Progress
2021-06-25 16:37:30 +03:00

21 lines
508 B
Kotlin
Vendored

// LANGUAGE: +SafeCallsAreAlwaysNullable
// ISSUE: KT-46860
interface A {
fun foo(): Int
}
fun takeInt(x: Int) {}
fun test_1(a: A) {
val x = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>a<!UNNECESSARY_SAFE_CALL!>?.<!>foo()<!>
takeInt(<!TYPE_MISMATCH!>x<!>) // should be an error
}
fun test_2(a: A?) {
if (a != null) {
val x = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>a<!UNNECESSARY_SAFE_CALL!>?.<!>foo()<!>
takeInt(<!TYPE_MISMATCH!>x<!>) // should be an error
}
}