Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the intersection of disjoint numbers in match analysis #14550

Merged
merged 2 commits into from
Feb 24, 2022

Conversation

dwijnand
Copy link
Member

The use of provablyDisjoint is a way of simplifying an intersection of
two types into the Empty space, using type comparing logic. However,
for types like (42L: Long) and (it: Int) (a constant type and a term
ref, of two different number types) the two types are provably disjoint,
but that doesn't mean that a "case it =>" won't match a "42L"
scrutinee. So we extend the logic to keep the intersection as it is
when numeric value types are in play.

Closes #14407

@SethTisue
Copy link
Member

SethTisue commented Feb 24, 2022

Very elegant that keeping provablyDisjoint from interfering is all that's needed.

I can't think of any other test coverage that should be added (even after discussing it with Dale, from every different angle either of us could think of).

The use of provablyDisjoint is a way of simplifying an intersection of
two types into the Empty space, using type comparing logic.  However,
for types like (42L: Long) and (it: Int) (a constant type and a term
ref, of two different number types) the two types are provably disjoint,
but that doesn't mean that a "case `it` =>" won't match a "42L"
scrutinee.  So we extend the logic to keep the intersection as it is
when numeric value types are in play.
Rather than trying to fix the types such that subtyping returns true for
these cases, we can rely on the numeric opt-out of using
provablyDisjoint and extend it to boxed numerics.
@dwijnand dwijnand merged commit 1b70511 into scala:main Feb 24, 2022
@dwijnand dwijnand deleted the patmat-unreachable-int-long branch February 24, 2022 18:52
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spurious reachability warning
4 participants