fix #31703, type intersection bug with chains of vars in invariant position #31747
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 problem here was the rule for intersecting var
T
inside e.g.Ref{T} ⊓ Ref{Foo{S}}
. We were intersectingFoo{S}
with the upper bound ofT
, and then (sometimes) doing a side check that that type is consistent. (The "sometimes" was added in #29380, basically as a different attempt to fix this same problem.) But that is not correct:T
needs to equalFoo{S}
, soFoo{S}
must be fully within its bounds. The catch is that that doesn't need to hold for all values ofS
though; we are free to restrictS
while forming the intersection. So here I changed the algorithm to always checkT.lb <: Foo{S} <: T.ub
, but with all variables treated as existential. Seems to work. Thissubtype_in_env_existential
trick might have other uses in intersection as well.Fixes #31703