mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-27 02:34:52 -06:00
954196a690
The formatter would normally just use the stringer for ast.Var which would swap in `_` for any wildcard variables (internally represented with a `$xx` syntax). This works fine except for AST dumped into the formatter that might have the same wildcard variable used multiple times. This can be seen by using partial evaluation creating multiple statements from a single original source. In the formatted output if we swap in `_` it can affect the resulting logic if they were supposed to be the same variable. The formatter now will check for any wild cards that show up >1 time in the AST passed in to be formatted. Any it finds will be assigned a new variable name like `__wilcardxx__` and in the resulting output will use that name instead of the `_` syntax. Fixes: #2053 Signed-off-by: Patrick East <east.patrick@gmail.com>