-
Notifications
You must be signed in to change notification settings - Fork 205
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
Inverse nullish coalescing operator #2214
Comments
Duplicate of #361. |
Oh, sorry for not noticing it. I tried searching a lot, but it seems like GitHub doesn't support searching for special symbols, and the original issue didn't contain the keywords I looked for. I will close this issue. But am I right that it is a small feature that shouldn't require much work? If so, can you please point me towards the correct location in the Dart SDK if I wanted to contribute? I tried walking through the repo but couldn't find the correct place for such a feature to be implemented. |
@aabounegm I can't really say how much would it cost to the team and if it's simple or not, but it's not as simple as simply hacking the SDK. It all starts with language design, which is what this repository is about, and the Dart language team usually spend a little more time than you would expect in this, because they don't need only to specify it in the language specification, but also consider all the implications this change would bring to the language, specially considering the future of the language evolution. Once specified, then the many different tools will have to implement it (CFE, analyzer, builder, VM etc) and it is also non-trivial and require efforts for many people from different teams. That said, maybe someone of the language team could point you better toward the proper way to doing this. Often people will only suggest the language feature, but I am sure that you can help more directly given you have the proper know-how and follow some guidelines... |
I understand, and I wanted to contribute, but I have no experience with the internals of Dart, unfortunately. I do know some C++ and am familiar with compilers a little bit, and I care a lot about following guidelines, so I was hoping I could be of help |
We already have the useful nullish coalescing operator
a ?? b
that is semantically equivalent toa == null ? b : a
. It would be great to also have an inverted null coalescing operatora !! b
meaninga == null ? null : b
. This would be useful in situations that require a non-null value for further computations, or otherwise benull
.For clarification, here is an actual example of code from a Flutter app I'm working on:
It would a lot less verbose if I could instead write it this way:
Similar to with
??
, it would also be adead_null_aware_expression
to writea !! b
whena
is non-nullable and it would evaluate tob
.As for the expression type, it makes sense for it be
T2?
, assuminga
has typeT1?
andb
has typeT2
. Of course, this also involves promotinga
to be non-nullable (T1
) inside theb
expression, like with the equivalent ternary operator expression.It seems relatively simple to implement since it would just be a syntactic sugar that could be de-sugared in the compiler frontend.
The text was updated successfully, but these errors were encountered: