Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/kt5455.kt
T
Evgeny Gerashchenko a3fdce8131 Highlighting "as Foo" for useless casts in gray.
#KT-6070 fixed
2014-12-08 17:30:47 +03:00

29 lines
551 B
Kotlin

//KT-5455 Need warning about redundant type cast
fun foo(o: Any): Int {
if (o is String) {
return (o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String<!>).length()
}
return -1
}
open class A {
fun foo() {}
}
class B: A()
fun test(a: Any?) {
if (a is B) {
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A<!>).foo()
}
}
fun test1(a: B) {
(a <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A?<!>)?.foo()
}
fun test2(b: B?) {
if (b != null) {
(b <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as A<!>).foo()
}
}