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

Add Matchable to the parents of Null in explicit nulls #12697

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Jun 3, 2021

Matchable should be a parent of Null in explicit nulls.

Fix the errors created by @bishabosha:

$ scala -Yexplicit-nulls
scala> def foo[T <: Matchable](t: T) = t match { case t: Null => () }
1 |def foo[T <: Matchable](t: T) = t match { case t: Null => () }
  |                                               ^
  |        this case is unreachable since type T and class Null are unrelated

scala> def foo[T <: Matchable](t: T) = t match { case null => () }                                               
1 |def foo[T <: Matchable](t: T) = t match { case null => () }
  |                                               ^^^^
  |Values of types Null and T
  |
  |where:    T is a type in method foo with bounds >: (?1 : Null) and <: Matchable
  | cannot be compared with == or !=

@noti0na1 noti0na1 requested a review from smarter June 3, 2021 12:14
@smarter smarter requested a review from sjrd June 3, 2021 15:19
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

That seems correct to me as a quick fix for now.

That said, I am still utterly convinced that we need to make Null extend AnyVal, which would also solve that problem by construction.

@noti0na1 noti0na1 merged commit cbb1e07 into scala:master Jun 4, 2021
@noti0na1 noti0na1 deleted the fix-parents-of-null branch June 4, 2021 01:24
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 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.

3 participants