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 comparing AnyVal | Null to Null and selecting in UnsafeNulls #13837

Merged
merged 3 commits into from
Oct 29, 2021

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Oct 27, 2021

When typing a Select under unsafeNulls, we should only strip Null from T | Null if T <:< ObjectType, so that unsafeNulls will have same behaviours as regular scala without explicit nulls.

This PR fixs comparing AnyVal | Null with Null using == and != in unsafeNulls:

val i: Int | Null = 0
if i != null then // ok
  println(i)

It also disallows selecting members of AnyVal on AnyVal | Null:

case class MyVal(i: Int) extends AnyVal:
  def printVal: Unit =
    println(i)

val v: MyVal | Null = MyVal(1)

import scala.language.unsafeNulls

v.printVal // error: value printVal is not a member of MyVal | Null

@noti0na1 noti0na1 requested a review from smarter October 27, 2021 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants