Skip to content

[NNBD] No error in Analyzer when non-nullable function may return null #42568

@sgrekhov

Description

@sgrekhov

The following code produces no issues in Analyzer but a compile error in CFE

import "dart:async";
main() {
  Future<int> f = new Future.value(42);
  f.then((_) {
    bool b = true;
    if (b) {
      return 42;
    }
  });
}

CFE output is

Error: A non-null value must be returned since the return type 'int' doesn't allow null.
f.then((_) {
       ^

There must be a compile error in Analyzer as well

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

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions