DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1587

Generative constructors can't redirect to a factory constructorDRT-W1587

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a generative constructor redirects to a factory constructor.

Example

The following code produces this diagnostic because the generative constructor C.a redirects to the factory constructor C.b:

class C {
  C.a() : this.b();
  factory C.b() => C.a();
}

Common fixes

If the generative constructor doesn't need to redirect to another constructor, then remove the redirect.

class C {
  C.a();
  factory C.b() => C.a();
}

If the generative constructor must redirect to another constructor, then make the other constructor be a generative (non-factory) constructor:

class C {
  C.a() : this.b();
  C.b();
}