don't report USELESS_CAST in case of casting to superype using 'as'
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user