Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/completion/kt36233.kt
T
Pavel Kirpichenkov 517688e163 [NI] Revise variance calculation method for completion mode
Before fix only one level of type arguments was used to determine variance of type variable to find out direction requirements.
This incorrect in general case, because outer variance affects subtyping deductions, for example:
Inv<Out<A>> <: Inv<Out<B>> => A <: B; B <: A, despite A and B are in covariant position if only one level is considered

^KT-36233 Fixed
2020-01-31 17:59:11 +03:00

14 lines
283 B
Kotlin
Vendored

// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -USELESS_CAST
class Inv<T>
class Out<out T>
fun <K> foo(y: K?) = Inv<Out<K>>()
fun <R> test(x: Inv<Out<R>>) {}
fun main() {
test<Int>(foo(null)) // type mismatch
test<Number>(foo(1 as Int)) // type mismatch
}