-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Dartanalyzer unused-variable hint is incorrect #29478
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
Comments
I think the analyzer is correct. The variable is used, but the value of the variable, assigned by |
That is an interesting observation, but: 1 class Foo {
2 Foo operator |(Foo _) {
3 return this;
4 }
5 }
6
7 main() {
8 var f = new Foo();
9 f |= new Foo();
10 }
The location the analyzer is pointing to is the variable itself (line 8) not the location of the Clearly the variable A variable can have several different assignments. If the value after a variable assignment is not used until the next assignment, then that specific assignment should be marked as being unnecessary, but not the variable itself. @lrhn Would you agree? |
Having some analysis to point out when a local variable is not referenced after an assignment (and hence the assignment is not necessary) would be useful. But it is different from what this was attempting to find, which is local variables that are not used at all. The point is not that you can eliminate the assignment, the point is that you can eliminate the variable by replacing both lines with |
Sure, but that can be said for this code as well: var x = new Foo();
x.bar() Here we can just do |
Duplicate of #27705 |
Here is an example where a variable is used but the analyzer thinks it is not used:
The text was updated successfully, but these errors were encountered: