Propagate orderings before unifying type parameters #12683
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR fixes a problem illustrated in the following code sample.
The code currently fails. The compiler complains that we give a X when we need a T2, and it believes that X >: T2.
We should know that X == T1 == T2 after the pattern matching, but currently the compiler assume that T2 <: X but not X == T2. This is because some part of ordering information does not propagate properly when we unify T1 to T2. In details, when we constrain the pattern match
Expr[T2] >:< Inv[T1]
, we can discover thatT1 == T2
. To record this piece of information into constraints, we first add the orderingT2 <:< T1
. After this, the constraints become:Then, when we add
T1 <:< T2
, the compiler discover that we already knowT2 <:< T1
, so it will unify T1 to T2. However, since we do not propagate orderings based on the fact thatT1 <:< T2
before the unification, and the compiler does not seem to propoerly handle the ordering information when unifying the two type parameters, the ordering thatT2 <:< T1 <:< X
will not get propagated. After the unification, the constraints becomeThis is why
(??? : X) <:< T2
does not type check. To fix this, we could propagate the bounds withaddLess
before weunify
the two type parameters.