phobos
phobos copied to clipboard
Allow assigning `null` to `Nullable`
Thanks for your pull request and interest in making D better, @GrimMaple! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:
- My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
- My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
- I have provided a detailed rationale explaining my changes
- New or modified functions have Ddoc comments (with
Params:
andReturns:
)
Please see CONTRIBUTING.md for more information.
If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.
Bugzilla references
Your PR doesn't reference any Bugzilla issue.
If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
Testing this PR locally
If you don't have a local development environment setup, you can use Digger to test this PR:
dub run digger -- build "master + phobos#8616"
Assigning null
is different than setting the Nullable state to null
, see: The problem with Nullable: nullable(null).isNull is false.
I'm not sure this is a good idea. @atilaneves
I think the real issue here is the name Nullable
.
If it were called Optional
or Maybe
, nobody would expect assigning null
to work like this in the first place, and nobody would be surprised to find out that it doesn't.
Unfortunately, we must keep the name Nullable
for compatibility, but perhaps we could rename it and make Nullable
an alias
?
Seeing how this PR isn't a particular hit with the D community, there is another solution I can propose: a compile-time error when trying to assign null
to nullable saying something like "Use nullify
instead"
@pbackus just renaming it to optional wouldn't be enough -- we would need to invent nullopt
or something
I'm not convinced of the utility of this either.
I don't see a lot of movement on this, so I'm going to reask: would making a error on assigning null
be more of an accepted solution?
I don't see a lot of movement on this, so I'm going to reask: would making a error on assigning
null
be more of an accepted solution?
It's already a compile-time error, isn't it?
I don't see a lot of movement on this, so I'm going to reask: would making a error on assigning
null
be more of an accepted solution?It's already a compile-time error, isn't it?
Well it's not a particularly great compile-time error. I was suggesting explicitly erroring "Use nullify
instead of assigning null"
I don't see a lot of movement on this, so I'm going to reask: would making a error on assigning
null
be more of an accepted solution?It's already a compile-time error, isn't it?
Well it's not a particularly great compile-time error. I was suggesting explicitly erroring "Use
nullify
instead of assigning null"
That sounds like a good idea.
If the null
is a valid value, (e.g. Nullable!string
), you should still be able to assign that. Otherwise (e.g. Nullable!int
) it can give an error.