Print undeclared var names - #9015
Merged
anderseknert merged 2 commits intoAug 13, 2026
Merged
Conversation
Local var rewriting runs before print calls are rewritten, so a diagnostic about a print operand named the generated var (`var __local0__ is undeclared`) rather than the one the author wrote. Map generated names back through RewrittenVars, as the template-string rewriter already does, and skip the redundant second walk of nested bodies that reported these errors twice. Fixes: open-policy-agent#5624 Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
Pin the positions, codes and messages in the compilecases corpus so that other Rego implementations can consume them. Reaching these diagnostics needs print calls left intact, so add an optional print_statements case option alongside strict and experimental_keywords. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
anderseknert
approved these changes
Aug 13, 2026
anderseknert
left a comment
Member
There was a problem hiding this comment.
This has been annoying for too long hacking on Regal, so this is great news. Thank you!
Benchmark Comparison (`e7c18bbc721841a54fbf67613c48f6423aed05dc` vs `8b1b42ee113bfe8bb91609eec951cd3d79c387a3`)
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: #5624
print() operands are safety-checked in a pass that runs after local vars have been renamed to generated ones, so
some x; print(x)reportedvar __local0__is undeclared instead of naming x. This maps the names back throughRewrittenVars, as the template-string rewriter already does for the same error.