Files
kotlin-fork/idea/testData/checker/infos/SmartCastsWithSafeAccess.kt
T
Denis Zharkov 00a78fce0c Get rid of special logic when check receiver
Instead of manually checking nullability when reporing UNSAFE_CALL_ERROR
just check if receiver type is subtype of receiver parameter

Make it in two steps
1. Check subtype with respect to smart casts but ignoring nullability (if it's not satisfied -> ERROR)
2. Check subtype with respect to nullability and smartcasts (record latter if needed)
2015-08-28 18:50:25 +03:00

36 lines
627 B
Kotlin
Vendored

interface A {
fun foo()
}
interface B : A {
fun bar()
}
interface C
interface D : A
fun test(a: A?) {
if (a != null && a is B?) {
<info descr="Smart cast to B">a</info>.bar()
}
if (a is B && a is C) {
<info descr="Smart cast to A">a</info>.foo()
}
if (a is B? && a is C?) {
<info descr="Smart cast to B?">a</info><info>?.</info>bar()
}
a<info>?.</info>foo()
if (a is B? && a is C?) {
a<info>?.</info>foo()
}
if (a is B && a is D) {
//when it's resolved, the message should be 'Smart cast to A'
a.<error>foo</error>
}
}