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

The late final local variable is already assignedDRT-W1457

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when the analyzer can prove that a local variable marked as both late and final was already assigned a value at the point where another assignment occurs.

Because final variables can only be assigned once, subsequent assignments are guaranteed to fail, so they're flagged.

Example

The following code produces this diagnostic because the final variable v is assigned a value in two places:

int f() {
  late final int v;
  v = 0;
  v += 1;
  return v;
}

Common fixes

If you need to be able to reassign the variable, then remove the final keyword:

int f() {
  late int v;
  v = 0;
  v += 1;
  return v;
}

If you don't need to reassign the variable, then remove all except the first of the assignments:

int f() {
  late final int v;
  v = 0;
  return v;
}