e72ddbcbfe
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.
36 lines
832 B
Kotlin
Vendored
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
|
|
}
|
|
} |