Skip to content

ast: don't leak generated locals in ref type errors#8902

Open
sspaink wants to merge 1 commit into
open-policy-agent:mainfrom
sspaink:fix/8897-leaked-local-in-type-error
Open

ast: don't leak generated locals in ref type errors#8902
sspaink wants to merge 1 commit into
open-policy-agent:mainfrom
sspaink:fix/8897-leaked-local-in-type-error

Conversation

@sspaink

@sspaink sspaink commented Jul 17, 2026

Copy link
Copy Markdown
Member

Fixes #8897

When a reference has a composite subject (e.g. [1, 2][i]) or a dynamic index term (e.g. [1, 2][input.x]), the compiler hoists that part of the ref into a generated local. Previously these locals leaked verbatim into type errors, e.g.:

undefined ref: __localq0__[i][j]

The type checker's var rewriter only knew how to map user variables back (via RewrittenVars), so anonymous generated locals were rendered as-is.

Record a mapping from each generated ref-subject/dynamic-operand local back to the original term value (in localVarGenerator.subjects) and use it when rendering refs in type errors, so the original expression is shown instead:

undefined ref: [1, 2][i][j]

When a reference has a composite subject (e.g. [1, 2][i]) or a dynamic
index term (e.g. [1, 2][input.x]), the compiler hoists that part of the
ref into a generated local. Previously these locals leaked verbatim into
type errors, e.g.:

    undefined ref: __localq0__[i][j]

The type checker's var rewriter only knew how to map user variables back
(via RewrittenVars), so anonymous generated locals were rendered as-is.

Record a mapping from each generated ref-subject/dynamic-operand local
back to the original term value (in localVarGenerator.subjects) and use
it when rendering refs in type errors, so the original expression is
shown instead:

    undefined ref: [1, 2][i][j]

Fixes open-policy-agent#8897

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local var name leaked in type error

1 participant