-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Better support for nullability in Option.apply and drop Option.fromNullable
#24238
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
Conversation
Option.applyOption.apply
Option.applyOption.apply and drop Option.fromNullable
|
|
||
| @experimental def testFromNullable = | ||
| val s: String | Null = "abc" | ||
| val sopt1: Option[String] = Option(s) // error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| extension (opt: Option.type) | ||
| @experimental | ||
| inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because it is useless now that we have Option.apply(A | Null)
|
I'm not sure about the conclusion in yesterday's core meeting. We need a clear answer now:
|
|
So from the notes of yesterday's core meeting:
As far as I'm concerned, this PR fixes inference with |
|
Indeed, but I'm still confused by the conclusion. I want a clear answer whether breaking the macro code is considered breaking compatibility. |
If we indeed have the inference fixed then there is probably no need to revert it
We haven't discussed issues with macros, but breaking macros is something that should be avoided. |
In this case, we can never add |
|
Regarding the macro case the issue is source code was trivial to fix and it becomes backward compatible with 3.7/2.13 stdlib - kitlangton/neotype#355 The only thing I haven't tested was usage in existing code, if it will still work then it should be fine to include these changes. |
|
I'm not against keeping the apply nullable, as long as everyone agrees on the changes. The meeting document was not clear about the two issues. |
Neither was the discussion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what the typer change does (and what it doesn't do).
For the rest, seems worth it if it works.
It behaves exactly as it behaved before, it just removes now The PR that improves this into a more general design is #24231 but that one needs more decisions and design of rules. |
Yes, this is not the most ideal signature for
Option.applybut it allows at least to dropOption.fromNullableand an easier migration to explicit nulls (no need to addfromNullableeverywhere).Superseed #24231 in the sense where we focus here on the nullability issue rather than the more global issue.
Reverts #24230
Relate to #24206