Skip to content

Dart and analyzer behaves in the different ways when return value is not set explicitly. #42459

@iarkh

Description

@iarkh

Dart VM version: 2.9.0-18.0.dev (dev) (Mon Jun 22 16:07:30 2020 +0200) on "windows_x64"

Here is a source code example:

main() {
  (x) {
    if (x)
      return 1;
    else
      return;
  } (true);
  print("OK");
}

Analyzer produces a compile error here.

Dart prints warning and then prints OK.

Seems like both tools should behave in the same way.

Sample output is:

$> dart test.dart
test.dart:6:7: Warning: Must explicitly return a value from a non-void function.
return;
^
OK

$> dartanalyzer
Analyzing test.dart...
error - The return value is missing after 'return'. - test.dart:6:7 - return_without_value
1 error found.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions