Fix #18246: correctly compute capture sets in TypeComparer.glb
#18254
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.
Intuitively,
glb(S1^C1, S2^C2)
should captureC1 ⊓ C2
, where⊓
denotes the glb of capture sets. When computingglb(tp1, tp2)
, iftp1
matchesCapturingType(parent1, refs1)
, it capturesC0 ++ refs1
whereC0
is the nested capture sets insideparent1
. Denote the capture set oftp2
withC2
, the result should capture(C0 ++ refs1) ⊓ C2
. Presumably,⊓
distributes over the union (++
); therefore(C0 ++ refs1) ⊓ C2
equalsC0 ⊓ C2 ++ refs1 ⊓ C2
.Previously, if
C2
is a subcapture ofrefs1
, it is simply dropped. However, based on the above reasoning, we haverefs1 ⊓ C2
equalsC2
; thereforeC0 ⊓ C2 ++ refs1 ⊓ C2
equalsC0 ⊓ C2 ++ C2
.C2
should not be dropped, but rather kept. This PR fixes the logic to behave correctly.Fixes #18246.