Repository navigation
fix(azure_policy): keep value-count names out of field() resolution - #874
Merged
Anand Krishnamoorthi (anakrish) merged 1 commit intoOct 29, 2026
Conversation
Inside a value count (`count: { value: [...], name: "location", ... }`),
`field('location')` and `field` conditions on a path equal to the count's
`name` resolved to the loop element instead of the resource field. A value
count's `name` is only reachable through `current()`; `field()` and field
conditions always read resource fields.
`resolve_count_binding` no longer matches field paths against value-count
names, and two branches that became unreachable are removed. `current()`
resolution is unchanged.
Tests cover `field()` and alias field conditions named like the count,
existenceCondition, names containing `[*]`, the `greater: 0` early exit,
`[if(...)]` field paths, nested value/field counts, and `current()` still
returning the element. Each match case has a twin that the pre-fix code
answers differently, except three labelled guards.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the Azure Policy field-resolution change.
No open issues 🎉
What changed in this PR
Fixes Azure Policy field resolution so value-count names no longer shadow resource fields. Named loop elements remain accessible through current(), while field-count binding behavior is preserved.
Changes:
- Removes value-count name matching from field resolution and related helper branches.
- Updates unit tests and adds 30 regression cases covering name collisions, nested counts, wildcard and dynamic paths, and related-resource evaluation.
| File | Description |
|---|---|
tests/azure_policy/cases/count.yaml |
Adds regression cases and guards for unchanged count behavior. |
src/languages/azure_policy/compiler/count.rs |
Restricts field binding resolution to field counts; updates documentation and unit tests. |
Review effort: Balanced
Anand Krishnamoorthi (anakrish)
approved these changes
Oct 29, 2026
Anand Krishnamoorthi (anakrish)
merged commit Oct 29, 2026
a31eeb4
into
microsoft:main
60 checks passed
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.
Summary
Fixes how a value count's
nameis resolved (compiler/count.rsresolve_count_binding).Inside a value count such as
count: { value: [...], name: "location", where: ... }, the expressionfield('location')returned the current loop element instead of the resource'slocation. The same happened forfieldconditions whose path equals the count'sname, including alias paths and dynamic[if(...)]paths. In Azure Policy a value count'snameis only reachable throughcurrent();field()and field conditions always read resource fields. This bug already existed on main.resolve_count_bindingno longer matches field paths against value-count names. Two branches that became unreachable are removed.current()resolution is unchanged.Testing
tests/azure_policy/cases/count.yamlhas 30 cases, covering:field('location'), alone and alongsidecurrent('location');fieldconditions named like the count;existenceCondition;[*];greater: 0early exit;[if(...)]field paths;current()still returning the element.cargo fmt --check;--all-targets --all-featuresand with--no-default-features;cargo build --all-targets,cargo test --doc,cargo test;--test aci,--test kata, and OPA with thetests/opa.passinglist (2875/0);cargo xtask test-no-std.Dependencies: none (based on main).