New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning to final variable is a static warning, not error #7062
Comments
The tests final_var_negative_test: Fail Are ok, see https://code.google.com/p/dart/source/detail?r=26519. |
Thanks! FYI, this test is still not valid: Assignment |
Removed this from the 1.6 milestone. |
Removed Oldschool-Milestone-1.6 label. |
It is an error in Dart2. |
final_for_in_variable_test/01: Fail
final_param_negative_test: Fail
final_var_negative_test: Fail
final_variable_assignment_test/01: Fail
final_variable_assignment_test/03: Fail
final_variable_assignment_test/04: Fail
final_variable_assignment_test/02: Fail
scope_negative_test: Fail
static_final_field2_negative_test: Fail
Spec
A final variable is a variable whose declaration includes the modifier final.
It is a compile-time error if a final instance variable that has been initialized at its point of declaration is also initialized in a constructor. It is a compile-time error if a final instance variable that has is initialized by means of an initializing formal of a constructor is also initialized elsewhere in the same constructor.
It is a compile-time error if a library, static or local variable v is final and v is not initialized at its point of declaration.
Attempting to assign to a final variable elsewhere will cause a NoSuchMethodError to be thrown, because no setter is defined for it. The assignment will also give rise to a static warning for the same reason.
A constant variable is a variable whose declaration includes the modifier const. A constant variable is always implicitly final. A constant variable must be initialized to a compile-time constant or a compile-time error occurs.
The text was updated successfully, but these errors were encountered: