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 class with no generative constructor declares not initialized non-nullable instance variable #40677

Closed sgrekhov closed 4 years ago

sgrekhov commented 4 years ago

According to the NNBD specification

It is an error if a mixin declaration or a class declaration with no generative constructors declares an instance variable with a potentially non-nullable type and no initializer expression unless the variable is marked with the late modifier.

But the following test fails

void foo() {}

class C {
  Function f;
  factory C.f() = D;
//        ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

class D implements C {
  Function f = foo;
  D();
}

main() {
  new C.f();
}

There is no expected error in dartanalyzer version 2.8.0-dev.9.0

Expected result: class C declares non-initialized instance variable and has no generative constructor therefore there must be an error

scheglov commented 4 years ago

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