-
Notifications
You must be signed in to change notification settings - Fork 75
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
Unused checker reports variable used in if-condition inside for_each block as unused #1214
Comments
Thank for reporting this @B-Schmidt. Closure support is very limited. I will take a look. |
I reproduced this:
Command:
Warning:
The checker marks
It didn't keep track that it was used in the previous iteration. VRL scripts don't allow loops so this cannot happen unless a closure is used. Will think a bit how to remove this warning. Since the checker doesn't handle closures, we could probably detect identifier usage inside closure and never consider the identifier again. |
Thinking about this some more with your explanation of what is actually happening, it could be argued that the assignment inside the closure is correctly detected as unused since the assignment on the last run through the loop would not be used. I am honestly unsure if that is more likely to lead to confusion like here or actually warn of a real issue. What did surprise me though is that the location of the issue is not updated to the latest assignment, which would have been less confusing to me. Looking at it in a simpler case, this behavior feels off to me: On the one hand, this would detect an issue in line 1 while the actual problem lies with line 3 (lines 1 and 2 being completely fine on their own):
On the other, this would not detect an issue at all despite the first assignment being completely unused:
Especially that latter one could miss problems e.g. with error handling. That should probably its own issue though. |
My take is that this is a bit confusing for users. The expression checker is a relatively new addition aiming to help users improve their VRL scripts. Once matured, the warnings can be treated as errors (in a future strict mode). Given this context and because closures are out of scope (for now) we don't want to make a decision right now, hence my idea to ignore identifiers which are used inside closures. |
In trying to implement a sort of
take_while
construct I have come across a variable being incorrectly marked as unused. Sample code to reproduce:This results in an
unused variable
warning for the linedone = false
despite the use ofdone
in the condition on line 6. Removing the expression as the warning suggests will of course fail to compile due to an undefined variable.The text was updated successfully, but these errors were encountered: