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)
This commit is contained in:
Denis Zharkov
2015-08-27 16:25:18 +03:00
parent 6ed6b2e298
commit 00a78fce0c
4 changed files with 53 additions and 91 deletions
+18 -6
View File
@@ -11,7 +11,7 @@ fun f9(a : A?) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
if (a is B) {
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to A">a</info>.foo()
}
a<info>?.</info>foo()
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
@@ -26,7 +26,19 @@ fun f9(a : A?) {
return;
}
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to A">a</info>.foo()
}
fun fAny(a : Any?) {
if (a is B) {
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
if (!(a is B)) {
return;
}
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
fun f10(a : A?) {
@@ -80,7 +92,7 @@ fun f12(a : A?) {
fun f13(a : A?) {
if (a is B) {
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to A">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
@@ -93,12 +105,12 @@ fun f13(a : A?) {
a<info>?.</info>foo()
}
else {
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to A">a</info>.foo()
}
a<info>?.</info>foo()
if (a is B && <info descr="Smart cast to B">a</info>.foo() == Unit) {
<info descr="Smart cast to B">a</info>.foo()
if (a is B && <info descr="Smart cast to A">a</info>.foo() == Unit) {
<info descr="Smart cast to A">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
+1 -1
View File
@@ -16,7 +16,7 @@ fun test(a: A?) {
}
if (a is B && a is C) {
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to A">a</info>.foo()
}
if (a is B? && a is C?) {