FIR: Weaken some UPPER_BOUND_VIOLATED restrictions
See test data at starProjectionInsteadOutCaptured.kt ^KT-49412 Fixed ^KT-50230 Relates ^KT-48044 Fixed
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +ProperTypeInferenceConstraintsProcessing
|
||||
|
||||
class A<T, F : T>
|
||||
fun foo(a: A<*, in CharSequence>) {}
|
||||
fun <T, U> coerce(t: T): U {
|
||||
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
|
||||
}
|
||||
|
||||
fun <T, U> coerce2(t: T): U {
|
||||
// We might report an error on unsound type reference Constrain<U, *, T>?, too
|
||||
val constrain: Constrain<U, *, T>? = null
|
||||
val bind = Bind(<!ARGUMENT_TYPE_MISMATCH!>constrain<!>) // WARNING: Type mismatch: inferred type is T but U was expected
|
||||
return bind.upcast(t)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +ProperTypeInferenceConstraintsProcessing
|
||||
|
||||
class A<T, F : T>
|
||||
fun foo(a: A<*, in CharSequence>) {}
|
||||
fun <T, U> coerce(t: T): U {
|
||||
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
|
||||
}
|
||||
|
||||
fun <T, U> coerce2(t: T): U {
|
||||
// We might report an error on unsound type reference Constrain<U, *, T>?, too
|
||||
val constrain: Constrain<U, *, T>? = null
|
||||
val bind = Bind(<!TYPE_MISMATCH, TYPE_MISMATCH!>constrain<!>) // WARNING: Type mismatch: inferred type is T but U was expected
|
||||
return bind.upcast(t)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
interface A
|
||||
interface B<X : A>
|
||||
interface C<E : A, F : B<E>>
|
||||
|
||||
fun foo1(c: C<out A, out B<*>>) {}
|
||||
|
||||
fun foo2(c: C<*, B<*>>) {}
|
||||
fun <T : B<*>> foo3(c: C<*, T>) {}
|
||||
fun <T : B<*>> foo4(c: C<out A, T>) {}
|
||||
Reference in New Issue
Block a user