Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/smartCastFork.fir.kt
T
Denis.Zharkov a33d9df0cd NI: Support forking inference with heuristics
Mostly, it only affects FIR

It partially allows to consider several variance of constraints like
A<Int> & A<T> <: A<X_var> that are mostly brought by smart casts

^KT-49542 Fixed
^KT-50489 Relates
2022-01-11 20:45:55 +03:00

26 lines
611 B
Kotlin
Vendored

// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface A<E> {
fun foo(): E
}
interface B : A<Int>
interface C : A<Long>
fun <T> bar(a: A<T>, w: T) {
baz(a, w) // OK in FE1.0
if (a is B) {
baz(a, 1) // OK in FE1.0
baz(a, w) // Type mismatch: Required Int, but found E
<!INFERENCE_UNSUCCESSFUL_FORK("it(B & A<T>) <: A<TypeVariable(F)>")!>baz<!>(a, "")
}
if (a is B || a is C) {
baz(a, w) // OK in FE 1.0 (Smart cast doesn't work), fail at FIR: it infers F to `LBU(Int, Long)` and then `w` is considered inapplicable
}
}
fun <F> baz(a: A<F>, f: F) {}