late_final_local_already_assigned
The late final local variable is already assigned.
Description
#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;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.