-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
cc @noti0na1 |
Since we couldn't update the std library right now, there is a "patch" function for extension (opt: Option.type)
@experimental
inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]] |
There was a discussion somewhere where @sjrd provided convincing reasons why |
The gist is: |
Well, yes, though Option's job is to subsume null, so it's not unexpected by any means. At least there is a fromNullable, I suppose |
I can see the reasoning, although this one's a big deal due to interop. So long as there's a Scalafix to do the rewrite (which seems doable) it's likely okay, but this change needs to be shouted from the rooftops: the use of |
I mean we're never actually going to change the behavior of |
Compiler version
3.5.2
Minimized example
Output
Gives a type error that expected
Foo
but gotNull
. Fine, except the point ofOption.apply
is that it is a null-safe wrapper intoOption
.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.The text was updated successfully, but these errors were encountered: