-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
?. operator should extend to remaining selectors #26240
Comments
If |
Clear - but it makes no sense to double check
if(elementToActivate != null) {
if(elementToActivate.classes != null {
...
}
} |
But without the extra check, the code is equivalent to
which can result in a null pointer dereference. You could argue that the ?. operator ought to short circuit everything to the right (in which case this is a language issue), but that's not the current definition. |
Uhhh - really?? To me it is logic that the first ?. operator makes all checks to the right unnecessary. I think someone should update the current definition. And - yes, I think this is a language issue! BTW: In C# for example operators are also short-circuiting |
It's certainly a modified semantics to say that Given that member access associates to the left (with Do you think there is a simple and consistent way to explain what is going On Tue, Apr 12, 2016 at 4:37 PM, Mike Mitterer [email protected]
Erik Ernst - Google Danmark ApS |
If you look at the following accesses as a chain of selectors, it makes a kind of sense to short-circuit the entire rest of the chain. It does have some consequences, just as for cascades - parentheses become meaningful and necessary in some cases. It won't have the same precedence as cascade - it's still like the normal |
@eernstg You say it looks like a tiny convenience - I think it's more. In my opinion it's just more logical to assume that the ?. is short-circuiting. A language feels good if it does what you think it should do. That's one reason why I like Dart. You know all the specs but the average programmer doesn't read all the specs... |
I updated this issue to reflect the requirement to change the language spec. |
This feature is included in Dart 2.12 (the null safety release, because with null safety we really did want to be able to distinguish whether |
The
?.
operator should extend to the remaining selectors.That is,
o?.x.y
should be legal, and not bomb on the.y
access.This issue was edited by @floitschG. Original content below:
Shows `INFO: The expression uses '?.', so can be 'null'``
It wants a ?. between "classes" and "add"
This is wrong - elementToActivate can be null but not "classes"
html_dartium:
The text was updated successfully, but these errors were encountered: