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 #21295: Restrict provablyDisjoint with Nothings in invariant type params. #21891

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Nov 5, 2024

If Foo[T] is invariant in T, we previously concluded that Foo[A] ⋔ Foo[B] from A ⋔ B. That is however wrong if both A and B can be (instantiated to) Nothing.

We now rule out these occurrences in two ways:

  • either we show that T corresponds to a field, like we do in the covariant case, or
  • we show that A or B cannot possibly be Nothing.

The second condition is shaky at best. I would have preferred not to include it. However, introducing the former without the fallback on the latter breaks too many existing test cases.

// sjrd: I will not be surprised when this causes further issues in the future.
// This is a compromise to be able to fix #21295 without breaking the world.
def cannotBeNothing(tp: Type): Boolean = tp match
case tp: TypeParamRef => cannotBeNothing(tp.binder.paramInfos(tp.paramNum))
Copy link
Member

Choose a reason for hiding this comment

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

Btw, I recently added .paramInfo to TypeParamRef, as in cannotBeNothing(tp.paramInfo).

…iant type params.

If `Foo[T]` is invariant in `T`, we previously concluded that
`Foo[A] ⋔ Foo[B]` from `A ⋔ B`. That is however wrong if both `A`
and `B` can be (instantiated to) `Nothing`.

We now rule out these occurrences in two ways:

* either we show that `T` corresponds to a field, like we do in the
  covariant case, or
* we show that `A` or `B` cannot possibly be `Nothing`.

The second condition is shaky at best. I would have preferred not
to include it. However, introducing the former without the fallback
on the latter breaks too many existing test cases.
@sjrd sjrd enabled auto-merge November 6, 2024 10:36
@sjrd sjrd merged commit 14c15b4 into scala:main Nov 6, 2024
26 checks passed
@sjrd sjrd deleted the fix-i21295 branch November 6, 2024 13:17
@WojciechMazur WojciechMazur added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Nov 6, 2024
WojciechMazur added a commit that referenced this pull request Nov 8, 2024
…invariant type params." to 3.6.2 (#21906)

Backports #21891 to the 3.6.2 branch.

PR submitted by the release tooling.
@WojciechMazur WojciechMazur added backport:done This PR was successfully backported. and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Nov 8, 2024
@WojciechMazur WojciechMazur added this to the 3.6.2 milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:done This PR was successfully backported.
Projects
None yet
3 participants