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;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。