-
Notifications
You must be signed in to change notification settings - Fork 207
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
Should null aware operators chain when we move to NNBD? #155
Comments
I poked around a couple of languages:
Personally, I feel we should short-circuit. It is a fairly common mistake to forget to do |
I want to fix that wart whether or not we get non-nullable types, but it's obviously a good time to do it since you will likely be touching null-aware code anyway. It's not always going to be an error otherwise: var text = x?.foo().toString(); // foo-toString or "null". It's not safe under refactoring, but that's probably unavoidable. Most short-circuiting operations are not. Short-circuiting is probably even required to make non-nullable types pleasant to work with. If If you want |
final v = RegExp('Hello, (.+)!')
.matchAsPrefix(input)
?.group(1)
?.split(RegExp(r'\s+'))
?.map(capitalize)
?.toList()
?? []; Here, only the first two methods can return actually final v = RegExp('Hello, (.+)!')
.matchAsPrefix(input)
?.group(1)
?.split(RegExp(r'\s+'))
.map(capitalize)
.toList()
?? []; or final v = RegExp('Hello, (.+)!')
.matchAsPrefix(input)
?.group(1)
.split(RegExp(r'\s+'))
.map(capitalize)
.toList()
?? []; |
@pschiffmann Short-circuiting is a good idea independently of non-nullable types. |
Decided: we will do this. |
Woo! |
Closing this, since we've made a decision. |
With NNBD, calling methods on the result of a null aware operator
whatsIt?.frobIt().fiddleSticks()
will always be a static error unlessfiddleSticks
is a method onObject
.Should we then just say that the
?.
propagates? That is, that an unguarded method call on the result of a guarded method call is treated as guarded?Arguments for:
Arguments against:
var a = whatsIt?.frobIt(); a.fiddleSticks();
will fail.Other issues/arguments?
The text was updated successfully, but these errors were encountered: