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

A constant redirecting constructor can't redirect to a non-constant constructorDRT-W1593

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a constructor marked as const redirects to a constructor that isn't marked as const.

Example

The following code produces this diagnostic because the constructor C.a is marked as const but redirects to the constructor C.b, which isn't:

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

Common fixes

If the non-constant constructor can be marked as const, then mark it as const:

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

If the non-constant constructor can't be marked as const, then either remove the redirect or remove const from the redirecting constructor:

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