Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt
T
Jinseong Jeon e72ddbcbfe FIR checker: differentiate UNSAFE_CALL from INAPPLICABLE_CANDIDATE
To do so, inside the root cause of inapplicable candidate errors,
we will record expected/actual type of receiver, if any.
That will help identifying inapplicable calls on nullable receiver.
2021-01-29 16:54:23 +03:00

36 lines
832 B
Kotlin
Vendored

// !LANGUAGE: +SafeCastCheckBoundSmartCasts
interface SomeClass {
val data: Any?
}
interface SomeSubClass : SomeClass {
val foo: Any?
}
fun g(a: SomeClass?) {
if (a as? SomeSubClass != null) {
// 'a' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass).<!UNSAFE_CALL!>foo<!>
(a as SomeSubClass).foo
}
val b = (a as? SomeSubClass)?.foo
if (b != null) {
// 'a' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass).<!UNSAFE_CALL!>foo<!>
(a as SomeSubClass).foo
}
val c = a as? SomeSubClass
if (c != null) {
// 'a' and 'c' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass).<!UNSAFE_CALL!>foo<!>
c.hashCode()
c.foo
}
}