-
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
Allow return;
in function returning FutureOr<void>
.
#3246
Comments
This is all working as intended. But it is somewhat tricky, so I'll comment on several things.
It could be claimed that However, you could also claim that it should be treated differently, because "the other return type" is We can't make the distinction because the "two return types" are combined using a union (the pipe operator in I would tend to say that the very type That was the conceptual part. For the technical part: The actual treatment of language/specification/dartLangSpec.tex Line 18917 in c13682a
For example, in the synchronous non-generator case (that is, a "normal" function, with no There are no errors for However, there are no special rules for This means that But you're not allowed to use
With With With |
I think we should fix it, by saying that We can then define "may return a value" and allow (And then carve out whatever exceptions we want to allow. I want none.) |
@eernstg Thanks for the explanation and suggestions:) I'm not a language engineer and I might never fully understand intricacies and vagueries of I'd see I'd see If a function is declared with a Similarly, in the case of I'd see I believe most people, unless bound by a particular specification or an implementation, will see things as such. |
Thanks! Dart has never had the notion of a procedure (that is, a behavioral abstraction where invocations do not return a value). So every function call returns a value, period. This is a good fit for dynamic invocations (which were very common in early Dart), and it avoids duplicating almost all of the language by having two kinds of functions everywhere. So we don't have the option to say that a particular function is a procedure. Next, we'd need to choose which value to return in situations where no value is specified by the developer; in general, the answer is the null object. So
If we want to specify that a function might return a In contrast, if we use the return type It is much more straightforward to use the special object
You can do that, and that's the semantics of
That's a bad type, so I won't try to fix it. However, if you use the return type
When
In Dart, the value of a This makes sense, for instance, in the case where we have a |
True but
I think Of course, that's not how C's interpret That's just my gut feeling, though – no real experience in C.
I don't see problem with duplication and why would I? there are thousands of instances in which I cannot express things succinctly no matter what language I choose. But I do wonder, if a language(not just Dart) want to assist in avoiding duplication in this particular case, why would it be willing to choose to deviate from the expected semantics of I believe, any deviation from user's interpretation of code, no matter how slight, is just wrong and should be minimized whenever feasible. |
This is currently working as specified. So moving this to be a language change request. I also, now, agree that you should always use |
return;
in function returning FutureOr<void>
.
It's not consistent with how
void
is treated at other places:fn1
andfn2
and compiler doesn't complain about missing explicit return inf1
(which it believes to be a must in non-void functions when compilingfn3
).return;
invoid function(s)
. So it's natural to expect it to work insideFutureOr
.Actual example:
The text was updated successfully, but these errors were encountered: