Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/unsoundness2.kt
T
Denis.Zharkov 9be4f818f4 FIR: Weaken some UPPER_BOUND_VIOLATED restrictions
See test data at starProjectionInsteadOutCaptured.kt

^KT-49412 Fixed
^KT-50230 Relates
^KT-48044 Fixed
2022-01-11 16:27:06 +03:00

23 lines
630 B
Kotlin
Vendored

// FIR_IDENTICAL
// SKIP_TXT
// !LANGUAGE: +ProperTypeInferenceConstraintsProcessing
fun main(args: Array<String>) {
val zero = coerce<Int, String>(0)
}
fun <T, U> coerce(t: T): U {
// Should be an error somewhere because this code leads to unsoundness
// We may report that `Constrain<U, *, in T>?` type definition is unsound or the call `Bind(constrain)`
// See KT-50230
val constrain: Constrain<U, *, in T>? = null
val bind = Bind(constrain)
return bind.upcast(t)
}
class Constrain<A, B : A, C : B>
class Bind<A, B : A, C : B>(val constrain: Constrain<A, B, C>?) {
fun upcast(c: C): A = c
}