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

-Yexplicit-nulls does not play nicely with Option.apply #22195

Open
j-mie6 opened this issue Dec 11, 2024 · 3 comments
Open

-Yexplicit-nulls does not play nicely with Option.apply #22195

j-mie6 opened this issue Dec 11, 2024 · 3 comments

Comments

@j-mie6
Copy link

j-mie6 commented Dec 11, 2024

Compiler version

3.5.2

Minimized example

//> using options -Yexplicit-nulls

class Foo
Option[Foo](null)

Output

Gives a type error that expected Foo but got Null. Fine, except the point of Option.apply is that it is a null-safe wrapper into Option.

Expectation

Realistically, its type needs to be def apply[A](x: A | Null): Option[A] when that flag is turned on, otherwise it's now useless.

@j-mie6 j-mie6 added the stat:needs triage Every issue needs to have an "area" and "itype" label label Dec 11, 2024
@Gedochao Gedochao added itype:enhancement area:nullability and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 11, 2024
@Gedochao
Copy link
Contributor

cc @noti0na1

@noti0na1
Copy link
Member

Since we couldn't update the std library right now, there is a "patch" function for Option defined at library/src/scala/runtime/stdLibPatches/Predef.scala

  extension (opt: Option.type)
    @experimental
    inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]]

@Gedochao
Copy link
Contributor

@noti0na1 potentially could be improved after #22043

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

3 participants