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

Fix #20897: Make Nothing ⋔ Nothing, as per spec. #21241

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jul 22, 2024

derivesFrom, used in provablyDisjointClasses, normally returns false when the receiver is Nothing. However, it returns true if the right-hand-side happens to be exactly Nothing as well. For the purpose of computing provablyDisjoint, that is not what we want.

The root issue was that we let the previous algorithm handle Nothing like a class type, which it is in dotc but not in the spec. That led to this mistake.

AnyKind suffers a similar issue, but already had special-cases in various places to mitigate it.

Instead of adding a new special-case for Nothing inside provablyDisjointClasses, we address the root issue. Now we deal with Nothing and AnyKind early, before trying any of the code paths that handle (real) class types.

`derivesFrom`, used in `provablyDisjointClasses`, normally returns
`false` when the receiver is `Nothing`. However, it returns `true`
if the right-hand-side happens to be exactly `Nothing` as well.
For the purpose of computing `provablyDisjoint`, that is not what
we want.

The root issue was that we let the previous algorithm handle
`Nothing` like a class type, which it *is* in dotc but not in the
spec. That led to this mistake.

`AnyKind` suffers a similar issue, but already had special-cases in
various places to mitigate it.

Instead of adding a new special-case for `Nothing` inside
`provablyDisjointClasses`, we address the root issue. Now we deal
with `Nothing` and `AnyKind` early, before trying any of the code
paths that handle (real) class types.
Copy link
Contributor

@EugeneFlesselle EugeneFlesselle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sjrd sjrd merged commit 2ea90c6 into scala:main Jul 23, 2024
28 checks passed
@sjrd sjrd deleted the fix-i20897 branch July 23, 2024 03:46
WojciechMazur added a commit that referenced this pull request Aug 27, 2024
#21458)

Backports #21241 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
WojciechMazur added a commit that referenced this pull request Dec 3, 2024
…22077)

Backports #21241 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
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.

area:match-types Match type reduction stuck on disjointness test for types of the form 1 | Nothing
3 participants