[FIR] Fix missing USELESS_CAST

`FirUselessTypeOperationCallChecker` always checks exact types matching for `as` operator

Simplify code of cast checker and utils

^KT-56629 Fixed
^KT-56615 Fixed
^KT-59820 Fixed
This commit is contained in:
Ivan Kochurkin
2023-10-19 20:35:03 +02:00
committed by Space Team
parent 2f8026f335
commit d50c6f1b6d
21 changed files with 209 additions and 121 deletions
@@ -13,7 +13,7 @@ fun g(a: SomeClass?) {
// 'a' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass)<!UNSAFE_CALL!>.<!>foo
(a <!USELESS_CAST!>as? SomeSubClass<!>)<!UNSAFE_CALL!>.<!>foo
(a <!USELESS_CAST!>as SomeSubClass<!>).foo
}
val b = (a as? SomeSubClass)?.foo
@@ -21,7 +21,7 @@ fun g(a: SomeClass?) {
// 'a' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass)<!UNSAFE_CALL!>.<!>foo
(a <!USELESS_CAST!>as? SomeSubClass<!>)<!UNSAFE_CALL!>.<!>foo
(a <!USELESS_CAST!>as SomeSubClass<!>).foo
}
val c = a as? SomeSubClass
@@ -29,7 +29,7 @@ fun g(a: SomeClass?) {
// 'a' and 'c' can be cast to SomeSubClass
a.hashCode()
a.foo
(a as? SomeSubClass)<!UNSAFE_CALL!>.<!>foo
(a <!USELESS_CAST!>as? SomeSubClass<!>)<!UNSAFE_CALL!>.<!>foo
c.hashCode()
c.foo
}