Skip to content

[NNBD] Analyzer and CFE behave differently for implicit return #42581

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
sgrekhov opened this issue Jul 6, 2020 · 4 comments
Closed

[NNBD] Analyzer and CFE behave differently for implicit return #42581

sgrekhov opened this issue Jul 6, 2020 · 4 comments
Labels
legacy-area-analyzer Use area-devexp instead. NNBD Issues related to NNBD Release

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Jul 6, 2020

The following code produces an error in VM and no issues in analyzer (both with --enable-experiment=non-nullable)

main() {
  (x) {
    if (x)
      return 1;
  } (true);
}

VM output is

D:\co19\Language\Statements\Return>dart --enable-experiment=non-nullable,nonfunction-type-aliases many_return_statements_t04.dart
many_return_statements_t04.dart:21:3: Error: A non-null value must be returned since the return type 'int' doesn't allow null.
(x) {                                                                                                                                              
^

Dart VM version: 2.9.0-20.0.dev (dev) (Wed Jul 1 11:29:16 2020 +0200) on "windows_x64"

@eernstg please clarify what is an expected behavior here

@sgrekhov
Copy link
Contributor Author

sgrekhov commented Jul 6, 2020

See also #39476

@eernstg
Copy link
Member

eernstg commented Jul 6, 2020

Blocked on dart-lang/language#1063: the current specification makes the function literal an error, and I'm proposing that we keep it like that even though it means that the analyzer will reject more programs.

@lrhn lrhn changed the title [NNBD] Analyzer and CFE bevahe differenly for implicit return [NNBD] Analyzer and CFE behave differently for implicit return Jul 7, 2020
@lrhn lrhn added the legacy-area-analyzer Use area-devexp instead. label Jul 7, 2020
@nshahan nshahan added the NNBD Issues related to NNBD Release label Jul 15, 2020
@mit-mit
Copy link
Member

mit-mit commented Oct 29, 2020

@eernstg did we determine what the right behavoir is?

@eernstg
Copy link
Member

eernstg commented Oct 29, 2020

Yes, when the end of a function with inferred return type can be reached (and null is implicitly returned), the inferred return type is made nullable and there is no error.

Implementation issue for CFE, #42743, is closed. The analyzer already did this.

@eernstg eernstg closed this as completed Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

5 participants