You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This solutino looks like it won't work to me. We are just tracking if we are inside an exists, not the actual variable the exists binds. Does it work correctly on the following code?
rule foo(X) => #Exists Y . { I #Equals Y }
In particular, this one should:
Warn about unused variable X
No error about variable Y.
Error about variable I, it's a universal variable only on the RHS of a rule, so should be ?I instead.
In particular, you need to track the boundVars set, instead of just tracking "am I inside an Exists/Forall".
so your code should check:
Am I under an Exists X . ..., if so, then add X to the bound vars set for when recursing into the .... (Same for Forall).
When checking variables (the KVariable case), if a variable is unbound, the same checks as before happen. But if a variable is bound, then it does not have the same restrictinos as before.
rule foo(X) => #Exists Y . { I #Equals Y }
[Warning] Compiler: Variable 'X' defined but not used. Prefix variable name with underscore if this is intentional.
Source(/home/radu/work/test/test.k)
Location(18,12,18,13)
18 | rule foo(X) => #Exists Y . { I #Equals Y }
. ^
[Error] Compiler: Found variable I on right hand side of rule, not bound on left hand side. Did you mean "?I"?
Source(/home/radu/work/test/test.k)
Location(18,32,18,33)
18 | rule foo(X) => #Exists Y . { I #Equals Y }
. ^
[Warning] Compiler: Variable 'I' defined but not used. Prefix variable name with underscore if this is intentional.
Source(/home/radu/work/test/test.k)
Location(18,32,18,33)
18 | rule foo(X) => #Exists Y . { I #Equals Y }
. ^
Added ?
rule foo(X) => #Exists Y . { ?I #Equals Y }
[Warning] Compiler: Variable 'X' defined but not used. Prefix variable name with underscore if this is intentional.
Source(/home/radu/work/test/test.k)
Location(18,12,18,13)
18 | rule foo(X) => #Exists Y . { ?I #Equals Y }
. ^
[Warning] Compiler: Variable '?I' defined but not used. Prefix variable name with underscore if this is intentional.
Source(/home/radu/work/test/test.k)
Location(18,32,18,34)
18 | rule foo(X) => #Exists Y . { ?I #Equals Y }
. ^~
If you look at the code, I modified GatherVarsVisitor. This tracks if we are in the LHS of a #Forall or #Exists, and if we find a variable, we add it to the bound set.
The original error message was thrown from CheckRHSVariables which relies on the visitor I just changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #2709
Just for reference, this is how the passing rule looks like at different stages:
@ehildenb please review
@PetarMax does this properly fix the issue you were having?