ast: name the enclosing rule in unsafe var errors on shared lines - #9011
Merged
sspaink merged 2 commits intoAug 13, 2026
Merged
Conversation
Rego allows several rules to be declared on one line, so the location in an unsafe var error doesn't always identify the rule the var was found in -- most confusingly when an identifier meant as a keyword isn't one in the OPA version being run, and silently starts a rule of its own. Name the enclosing rule when it shares a line with a differently named rule, leaving the common case of one rule per line unchanged. Fixes: open-policy-agent#4967 Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
The evaluation corpus in v1/test/cases, which Rego implementations outside this repository consume as a conformance suite, cannot express a policy that fails to compile, so nothing shared pins the errors OPA reports before evaluation begins. Add v1/test/compilecases as a sibling of it, seeded with the unsafe var cases from open-policy-agent#4967, each pinning the error code, position and message of the diagnostics a policy must produce. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
Benchmark Comparison (`7aaf1c538fe602581690253cf6adf2cb5519d0d9` vs `fb8353d50a64ad594ef1600826923493524dd76e`)
This comment was automatically generated by the benchmarks workflow. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix: #4967
Safety errors now name the enclosing rule when its line hold a rule of a different name.
Similar to the existing evaluation compliance tests (
v1/test/cases), addedv1/test/compilecasesto be a place we can put compile compliance tests. Just the test cases covering this change. If we are happy with this layout I can follow up with adding more tests.