Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/kt5455.kt
T
2015-10-14 20:39:35 +03:00

29 lines
404 B
Kotlin
Vendored

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