-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Variables that are only used for swapping are marked as unused #1832
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
Definitely a bug; will be annoying to fix, though, since this is the only thing that makes the "unused variables" analysis non-local. |
How does it make it non-local? If you just perform the same marking of used for the LHS of the swap as you're doing for the RHS, I think that's plenty good enough. |
Well, the question is, suppose I have the following program:
Where x and y get swapped, but never used. If I treat both sides of a swap the same way I would treat the RHS of an assignment, then the compiler won't print a warning for this program. Arguably that's wrong -- x and y are both swapped, but neither is actually, used. OTOH, if others think that a conservative approximation (not warning for the above case) is acceptable, I'm ok with doing the simplest thing. Does that make sense? |
A conservative thing that at least doesn't emit spurious warnings is good enough for me. A 'correct' analysis would be awesome, but probably not worth the extra complexity. |
I'm ok with doing the easy thing here :-) |
IMO, the "unused" warning should be per-assignment, not per-variable.
should warn because the first assignment to x is unused.
should warn because the second assignment to x is unused. Finally, the original example,
should warn because the second assignment to x is unused. |
I agree, actually. The last-use pass already has this information, and is probably easier to extend than the typestate code. We could move unused variable analysis into that pass. |
The original bug seems to have been fixed. I don't know how to add a test case for it, because there doesn't seem to be a way (in lint) to turn the unused-variable warning into an error. As for @jruderman 's proposal, I'm going to turn that into a separate bug. |
This causes a warning that x is unused:
The text was updated successfully, but these errors were encountered: