Files
kotlin-fork/compiler/testData/diagnostics/tests/regressions/kt7804.kt
T
Denis.Zharkov 2ecba6ac39 Remove WITH_NEW_INFERENCE directive from all tests
This directive anyway does not make test run twice with OI, and with NI
It only once run the test with specific settings (// LANGUAGE)
and ignores irrelevant (OI or NI tags)
2021-05-25 13:28:26 +03:00

65 lines
894 B
Kotlin
Vendored

// See also KT-7804 (Wrong type inference of kotlin.Any? was for 'a' without explicit type)
fun <T> foo(a: T) = a
class A
fun <T> test(v: T): T {
val a = if (v !is A) {
foo(v) <!USELESS_CAST!>as T<!>
}
else {
v
}
val t: T = a
return t
}
fun <T> test2(v: T): T {
val a = if (v !is A) {
foo(v) <!USELESS_CAST!>as T<!>
}
else {
v <!USELESS_CAST!>as T<!>
}
val t: T = a
return t
}
fun <T> test3(v: T): T {
val a = if (v !is A) {
foo(v)
}
else {
v
}
val t: T = a
return t
}
fun <T> test4(v: T): T {
val a: T = if (v !is A) {
foo(v) <!USELESS_CAST!>as T<!>
}
else {
v
}
val t: T = a
return t
}
fun <T> test5(v: T): T {
val a: T = if (v !is A) {
foo(v)
}
else {
v
}
val t: T = a
return t
}