Fix #6314: match type unsoundness #6319
Merged
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.
This PR fixes several match issues
The first issue was that the algorithm assumes types in an
AndTypealways came in the same order, so it wrongly concluded thatX & YandY & Typeare non intersecting from the fact thatXandYare non intersecting. The updated logic checks both permutations, and simply get stuck whenTypeis abstract, which fixes the unsoundness.The second issue is related to the
Singleton. This marker type needs to be taken it into account by the intersection algorithm, see the added test case.Finally the previous handling of abstract type was problematic a showed by several of the examples in #6314. The logic is updated to do a sub-type check where all the abstract types (members or parameters) are replace by
WildcardType. If the scrutinee is not a subtype of a pattern, but it is with wildcards, then the type shouldn't reduce.