Skip to content
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

Closed
scheglov opened this issue Nov 30, 2012 · 9 comments
Closed

Assigning to final variable is a static warning, not error #7062

scheglov opened this issue Nov 30, 2012 · 9 comments
Labels
area-test Cross-cutting test issues (use area- labels for specific failures; not used for package:test). closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@scheglov
Copy link
Contributor

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.


@anders-sandholm
Copy link
Contributor

Removed this from the M2 milestone.
Added this to the M3 milestone.

@anders-sandholm
Copy link
Contributor

Removed this from the M3 milestone.
Added this to the M4 milestone.

@larsbak
Copy link

larsbak commented May 28, 2013

Removed this from the M4 milestone.
Added this to the M5 milestone.

@sgjesse
Copy link
Contributor

sgjesse commented Aug 22, 2013

The tests

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

Are ok, see https://code.google.com/p/dart/source/detail?r=26519.

@scheglov
Copy link
Contributor Author

Thanks!

FYI, this test is still not valid:
language/getter_no_setter_test/01

Assignment
Let T be the static type of e1. It is a static type warning if T does not have an accessible instance setter named v=.

@kasperl
Copy link

kasperl commented Jun 4, 2014

Removed this from the M5 milestone.
Added this to the 1.6 milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the 1.6 milestone.
Added Oldschool-Milestone-1.6 label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-1.6 label.

@scheglov scheglov added Type-Defect area-test Cross-cutting test issues (use area- labels for specific failures; not used for package:test). labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Feb 29, 2016
@matanlurey
Copy link
Contributor

It is an error in Dart2.

@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-test Cross-cutting test issues (use area- labels for specific failures; not used for package:test). closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants