NI: remove separation of variable fixation order by constraint kind

The commit partially reverts ec4d9d2f1f

^KT-37914 Fixed
This commit is contained in:
Victor Petukhov
2020-05-19 21:09:17 +03:00
parent 874fa5b998
commit 12db3d6e83
6 changed files with 129 additions and 17 deletions
@@ -0,0 +1,60 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNCHECKED_CAST
// Issue: KT-37914
interface I
fun <R, U : R> castToSubtype(obj: R) = obj as U
fun <T> select(vararg x: T) = x[0]
fun <S> materialize(): S = null as S
// Case 1 (using intermediate supertype)
/*
Constraint system:
R:
TypeVariable(U) <: TypeVariable(R)
I <: TypeVariable(R)
U:
I >: TypeVariable(U)
Foo<TypeVariable(P)> >: TypeVariable(U)
T:
Foo<Any> <: TypeVariable(T)
Bar<TypeVariable(P)> <: TypeVariable(T)
Fixation order before the fix: R, U, T, P
Fixation order after the fix: R, T, P, U
`U` has begun to have lower priority so it can be fixed to more specific type (to `Foo<Any>` instead of `I`).
*/
interface Foo<T> : I
class Bar<T>(val x: Foo<T>) : Foo<T>
fun main2() {
select(
materialize<Foo<Any>>(),
Bar(
castToSubtype(materialize<I>()) // NI: "required Foo<Any>, found I" afther the commit, OI OK
)
)
}
// Case 2 (using deep supertype)
interface Foo1<Y> : I
interface Foo2<Y> : Foo1<Y>
class Bar1<P>(val x: Foo2<P>) : Foo2<P>
fun main1() {
select(
materialize<Foo2<Any>>(),
Bar1(
castToSubtype(materialize<I>()) // NI: "required Foo<Any>, found I" afther the commit, OI OK
)
)
}
@@ -0,0 +1,47 @@
package
public fun </*0*/ R, /*1*/ U : R> castToSubtype(/*0*/ obj: R): U
public fun main1(): kotlin.Unit
public fun main2(): kotlin.Unit
public fun </*0*/ S> materialize(): S
public fun </*0*/ T> select(/*0*/ vararg x: T /*kotlin.Array<out T>*/): T
public final class Bar</*0*/ T> : Foo<T> {
public constructor Bar</*0*/ T>(/*0*/ x: Foo<T>)
public final val x: Foo<T>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Bar1</*0*/ P> : Foo2<P> {
public constructor Bar1</*0*/ P>(/*0*/ x: Foo2<P>)
public final val x: Foo2<P>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Foo</*0*/ T> : I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Foo1</*0*/ Y> : I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Foo2</*0*/ Y> : Foo1<Y> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}