Skip to content

strict equality + explicit nulls = paradox #11469

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

Open
megri opened this issue Feb 18, 2021 · 3 comments
Open

strict equality + explicit nulls = paradox #11469

megri opened this issue Feb 18, 2021 · 3 comments

Comments

@megri
Copy link
Contributor

megri commented Feb 18, 2021

Compiler version

3.0.0-RC1

Compiler settings

flags: -Yexplicit-nulls + -language:strictEquality

Minimized code

def couldBeNull: String|Null =if couldBeNull == null then -1 else couldBeNull.length 

Output

-- Error: <redacted>/app.scala:16:7
16 |    if couldBeNull == null then -1 else couldBeNull.length
   |       ^^^^^^^^^^^^^^^^^^^
   | Values of types Null | String and Null cannot be compared with == or !=
one error found
one error found

Expectation

no error found

@megri
Copy link
Contributor Author

megri commented Feb 19, 2021

Found #10850. Seems strict equality is broken for now..

@mohe2015
Copy link

mohe2015 commented Jun 1, 2024

Still seems to be an issue with

@main def hello(): Unit =
  val test = if (true) {
    null
  } else {
    "test"
  }
  println(test == null)
  println(null == test)

As far as I understand scala 3 now has it's own stdlib. Does that mean we can add

given canEqualNullableNull[T]: CanEqual[T | Null, Null] = CanEqual.derived
given canEqualNullNullable[T]: CanEqual[Null, T | Null] = CanEqual.derived

or similar to the scala 3 stdlib?

@noti0na1
Copy link
Member

noti0na1 commented Jun 1, 2024

Still seems to be an issue with

@main def hello(): Unit =
  val test = if (true) {
    null
  } else {
    "test"
  }
  println(test == null)
  println(null == test)

Which version are you using, and what error are you getting?
The code can be compiled with explicit nulls on my side.

Oh I remember the original issue is related to strictEquality.
Since that featurn is not actively maintained, we don't have any comment for this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants