don't report USELESS_CAST in case of casting to superype using 'as'

This commit is contained in:
Dmitry Jemerov
2015-04-24 16:18:54 +02:00
parent f374eec8f1
commit 8258d72e23
4 changed files with 37 additions and 8 deletions
+7 -2
View File
@@ -9,10 +9,15 @@ fun test() : Unit {
checkSubtype<Int>(x as Int)
checkSubtype<Int>(y <!USELESS_CAST!>as Int<!>)
checkSubtype<Int?>(x <!USELESS_CAST!>as Int?<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as Int?<!>)
checkSubtype<Int?>(y as Int?)
checkSubtype<Int?>(x <!USELESS_CAST!>as? Int<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as? Int<!>)
checkSubtype<Int?>(x <!USELESS_CAST!>as? Int?<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as? Int?<!>)
checkSubtype<Int?>(y as? Int?)
val <!UNUSED_VARIABLE!>s<!> = "" <!USELESS_CAST!>as Any<!>
("" as String?)?.length()
(@data("" as String?))?.length()
([data]( "" as String?))?.length()
Unit
}
@@ -15,6 +15,6 @@ fun bar() {
val x = X
x.foo()
X.foo()
(X <!USELESS_CAST!>as C<!>).foo()
(X as C).foo()
((if (1<2) X else Y) <!USELESS_CAST!>as C<!>).foo()
}
@@ -13,16 +13,16 @@ class B: A()
fun test(a: Any?) {
if (a is B) {
(a <!USELESS_CAST!>as A<!>).foo()
(a as A).foo()
}
}
fun test1(a: B) {
(a <!USELESS_CAST!>as A?<!>)?.foo()
(a as A?)?.foo()
}
fun test2(b: B?) {
if (b != null) {
(b <!USELESS_CAST!>as A<!>).foo()
(b as A).foo()
}
}