Skip to content

[NNBD] No error in analyzer for empty factory constructor #42337

@sgrekhov

Description

@sgrekhov
class C {
  factory C.f() {}
}

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

The code above produces no error in analyzer with --enable-experiment=non-nullable

dartanalyzer --enable-experiment=non-nullable,nonfunction-type-aliases private_and_public_t01.dart
Analyzing private_and_public_t01.dart...
hint - This function has a return type of 'C', but doesn't end with a return statement. - private_and_public_t01.dart:34:3 - missing_return
hint - The value of the local variable 'c' isn't used. - private_and_public_t01.dart:38:5 - unused_local_variable
2 hints found.

In VM it is an error

dart --enable-experiment=non-nullable,nonfunction-type-aliases private_and_public_t01.dart
private_and_public_t01.dart:34:11: Error: A non-null value must be returned since the return type 'C' doesn't allow null.
- 'C' is from 'private_and_public_t01.dart'.
factory C.f() {}
        ^

Dart VM version: 2.9.0-15.0.dev (dev) (Thu Jun 11 10:03:39 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