[CP] Disallow final fields to be used in a const context in analyzer #54232
Labels
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
cherry-pick-approved
Label for approved cherrypick request
merge-to-stable
Commit(s) to merge
988c301
Target
stable
Prepared changelist for beta/stable
https://dart-review.googlesource.com/c/sdk/+/339820
Issue Description
If a final field is assigned in its declaration (not in a generative constructor) in a class with a constant constructor, constant evaluation incorrectly allows it to be used as a constant. This results in the
prefer_const_constructors
lint incorrectly suggestingconst
can be added as well, with no indication that it will result in a compilation error, making it quite easy to get into this situation as it's enabled by default influtter_lints
.What is the fix
From @kallentu:
Why cherry-pick
Developers can work around the issue by making some structural adjustments or ignoring the lint, but it may result in confusion from developers and issues uncaught by the analyzer. Also ignoring a lint can result in missing lints in the future.
See an example of the effects of this issue in flutter/devtools#6891.
Risk
low
Issue link(s)
#53927, flutter/devtools#6891
Extra Info
This has a test and fixes a regression in the analyzer's constant context. It doesn't affect the compilers, so issues technically would be caught by those later on or before deployment.
The text was updated successfully, but these errors were encountered: