Files
releases/v1
Johan Fylling 03646dde18 topdown: Fix PE not namespacing vars in comprehensions nested inside every (#8816)
Partial-eval doesn't properly namespace in-scope vars inside
comprehensions when they're nested inside an `every` statement.

E.g. PE on `data.test.p = true` for the policy:

```rego
package test
p if {
	every x in input.x {
		{y | y := input.y; y < x}
	}
}
```

will emit:

```rego
every __local0__1, __local1__1 in input.x { 
	{__local2__ | __local2__ = input.y; lt(__local2__, __local1__)} 
}
```

Notice how the comprehension makes a reference to `__local1__`, which
has been namespaced to `__local1__1` in the outer scope, making the
result query invalid.

This fix checks for comprehension terms inside the `every`-body and
amends them. Which gives us the updated result query:

```rego
every __local0__1, __local1__1 in input.x {
 	{__local2__1 | __local2__1 = input.y; lt(__local2__1, __local1__1)}
 }
```

where vars inside the comprehension are now namespaced.

Note: this is a pretty narrow edge-case, so I wouldn't expect many real
cases in the wild.

---------

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2026-06-24 13:22:47 +02:00
..
2025-10-10 17:51:02 +02:00
2026-03-06 22:07:35 +00:00
2026-05-13 13:11:27 +02:00
2024-12-12 15:27:34 +01:00