dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.58k forks source link

NNBD. No error if the body of a method, function, getter, or function expression with a potentially non-nullable return type may complete normally #40396

Closed sgrekhov closed 4 years ago

sgrekhov commented 4 years ago

NNBD specification reads

It is an error if the body of a method, function, getter, or function expression with a potentially non-nullable return type may completely normally.

In fact there are no any error. Example

class A {}

class C {
  static A sTest() {}

  A mTest() {}

  A get gTest {}
}

A test() {}

main() {
  C.sTest();
  C c = new C();
  c.mTest();
  c.gTest;
  test();
}

Tested on dartanalyzer version 2.8.0-dev.6.0

eernstg commented 4 years ago

It might be helpful to note that the expected errors are on the declarations of sTest, mTest, gTest, and test, because each of them has the body {} which may (indeed will) complete normally, and each of them returns A, which is a potentially non-nullable type.

scheglov commented 4 years ago

https://dart-review.googlesource.com/c/sdk/+/135582