Skip to content

It is a compile-time error to use "return;" without value. #34319

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

Closed
scheglov opened this issue Aug 30, 2018 · 8 comments
Closed

It is a compile-time error to use "return;" without value. #34319

scheglov opened this issue Aug 30, 2018 · 8 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-stale Closed as the issue or PR is assumed stale status-blocked Blocked from making progress by another (referenced) issue

Comments

@scheglov
Copy link
Contributor

scheglov commented Aug 30, 2018

Tests:
language_2/void/return_future_or_void_sync_error4_test/none
language_2/void/return_future_future_or_void_async_error1_test/none
language_2/void/return_future_or_future_or_void_sync_error2_test/none
language_2/invalid_returns/async_invalid_return_03_test/none
language_2/invalid_returns/async_invalid_return_02_test/none
language_2/invalid_returns/sync_invalid_return_01_test/none
language_2/invalid_returns/sync_invalid_return_04_test/none
language_2/invalid_returns/async_invalid_return_01_test/none
language_2/invalid_returns/sync_invalid_return_02_test/none
language_2/invalid_returns/sync_invalid_return_05_test/none
language_2/invalid_returns/sync_invalid_return_03_test/none
language_2/invalid_returns/async_invalid_return_00_test/none
language_2/invalid_returns/sync_invalid_return_00_test/none
language_2/invalid_returns/async_invalid_return_04_test/none

co19_2/Language/Errors_and_Warnings/static_warning_t01
co19_2/Language/Statements/Return/no_expression_function_t01
co19_2/Language/Statements/Return/no_expression_function_t16
co19_2/Language/Statements/Return/no_expression_function_t10
co19_2/Language/Statements/Return/many_return_statements_t02
co19_2/Language/Statements/Return/no_expression_function_t07
co19_2/Language/Statements/Return/no_expression_function_t11
co19_2/Language/Statements/Return/no_expression_function_t04
co19_2/Language/Statements/Return/no_expression_not_function_t01
co19_2/Language/Statements/Return/no_expression_function_t08
co19_2/Language/Statements/Return/no_expression_function_t09
co19_2/Language/Statements/Return/no_expression_function_t05
co19_2/Language/Statements/Return/no_expression_function_t02
co19_2/Language/Statements/Return/no_expression_function_t03

@scheglov scheglov added the area-test Cross-cutting test issues (use area- labels for specific failures; not used for package:test). label Aug 30, 2018
@kmillikin kmillikin added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed area-test Cross-cutting test issues (use area- labels for specific failures; not used for package:test). labels Aug 31, 2018
@kmillikin
Copy link

It's valid if the return type is void, dynamic, or Null (or if the flattened return type is for asynchronous non-generator functions). For the other cases, we have been discussing with the language team that this will probably have to continue to be a warning, because making it an error is a breaking change.

I guess the issue for the language team is to make a decision and update the feature spec at https://github.com/dart-lang/sdk/blob/master/docs/language/informal/invalid_returns.md.

@eernstg
Copy link
Member

eernstg commented Sep 12, 2018

@kmillikin, you mention updating invalid_returns.md, but it's not obvious to me what we'd make a decision about. Could you elaborate?

Maybe it's got to do with the errors/warnings listed in #34349?

@kmillikin
Copy link

Yes, exactly. It was decided that return; from a function with a return type other than void, dynamic, or Null would be a warning and not an error. The feature spec does not say that (it says "is an error" which seems wrong unless it's just being vague and you mean it's a warning.)

The feature spec needs a number of other updates:

It does not say what happens for an invalid return in the first part. Is it a compile-time error? Warning? Runtime error? Something else? It should be made clear.

It only characterizes the valid returns and does not ever say "and all other returns are invalid" which it should.

The second part says that the invalid returns are errors. Are they compile-time errors? Runtime errors? If it's meant to be an alternative and equivalent treatment then each part should stand alone. As I mentioned above, it should be explicit about which are errors and which are warnings.

@eernstg
Copy link
Member

eernstg commented Sep 12, 2018

Indeed, thanks! I hadn't seen that return_without_value was among those, and we certainly need to update several documents (I thought that it would only involve dartLangSpec.tex). Added a note about this to #34349.

@kmillikin
Copy link

Also: it's simultaneously in status "implemented" and "ready for implementation" which (pedantically) isn't wrong but it's more confusing than simply "implemented".

And can we please rename this feature spec to invalid-returns.md? It's the only one that has an underscore in its name and I keep forgetting that when I go to search for it. Since we've linked to it, we could leave a document at invalid_returns.md that says it's moved.

@eernstg
Copy link
Member

eernstg commented Oct 4, 2018

This CL adjusts dartLangSpec.tex such that the compile-time error mentioned above is changed to a warning.

dart-bot pushed a commit that referenced this issue Oct 24, 2018
Partially resolves issue #34349.
Also note that #34365 and #34319 are affected by this change.

Change-Id: I1d9023464090ff2c07f9dc062353202ddb82ba25
Reviewed-on: https://dart-review.googlesource.com/c/78121
Reviewed-by: Leaf Petersen <[email protected]>
@eernstg
Copy link
Member

eernstg commented Mar 6, 2019

Said CL was landed as e4e82da.

@kmillikin wrote:

status .. confusing .... rename .. to invalid-returns.md

The status is now 'background material .. please consult the language specification'. This would be less ambiguous, and it makes the need to rename less urgent, so I'll consider those issues to be resolved at this point.

invalid returns are errors. Are they compile-time errors? Runtime errors?

The language specification text is explicit on this topic, for example here, so I think this has been resolved as well:

It is a compile-time error if $s$ is \code{\RETURN{};},
unless $T$ is \VOID, \DYNAMIC, or \code{Null}.

I believe that there are no remaining 'area-language' issues here, so I'll remove that label.

@eernstg eernstg added status-blocked Blocked from making progress by another (referenced) issue and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Mar 6, 2019
@eernstg
Copy link
Member

eernstg commented Mar 6, 2019

The treatment of warnings in Dart is currently being revisited by the language team, cf. #36126 and #36127, so I'm marking this issue as blocked until it has been decided exactly which situations will be errors and which ones will be warnings (if any).

@a-siva a-siva added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Mar 7, 2019
@lrhn lrhn added the closed-stale Closed as the issue or PR is assumed stale label Apr 9, 2025
@lrhn lrhn closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-stale Closed as the issue or PR is assumed stale status-blocked Blocked from making progress by another (referenced) issue
Projects
None yet
Development

No branches or pull requests

5 participants