Repository navigation
Fix undefined assignments and comprehension heads in RVM - #883
Open
Mark Birger (kusha) wants to merge 1 commit into
Open
Mark Birger (kusha) wants to merge 1 commit into
Mark Birger (kusha) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical nested-comprehension failures route control to the wrong loop or leave inner contexts active, producing incorrect results in run-to-completion mode and requiring fixes with regressions in both execution modes.
2 open issues
What changed in this PR
This PR updates the Rego-to-RVM compiler to reject undefined assignments and omit undefined comprehension entries, aligning these paths with interpreter behavior while preserving valid false-like values.
Changes:
- Add definedness guards before assignment destructuring, including wildcard assignments.
- Guard array comprehension values and object comprehension keys and values before yielding.
- Add four regression cases covering run-to-completion and suspendable execution, compared against the interpreter.
| File | Description |
|---|---|
tests/rvm/rego/cases/undefined_values.yaml |
Adds regression coverage for undefined values, fallback behavior, and valid false-like values. |
src/languages/rego/compiler/queries.rs |
Adds definedness guards to array and object comprehension heads. |
src/languages/rego/compiler/destructuring.rs |
Guards assignment right-hand sides before destructuring. |
Review effort: Balanced
Comment on lines
+46
to
+50
| self.emit_instruction( | ||
| Instruction::Guard { | ||
| register: rhs_reg, | ||
| mode: GuardMode::NotUndefined, | ||
| }, |
Comment on lines
+174
to
+178
| self.emit_instruction( | ||
| Instruction::Guard { | ||
| register: value_register, | ||
| mode: GuardMode::NotUndefined, | ||
| }, |
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
Fix two RVM compiler paths that allow undefined values to survive where Rego requires the current rule-body attempt or comprehension iteration to fail.
GuardMode::NotUndefinedcheck after compiling the RHS of:=, before destructuring. This covers named variables and_.For example, with input
{}, this rule must be undefined rather than returntrue:Separately,
[input.missing | true]must return[], not an array containing internalUndefined. Object comprehension entries with undefined keys or values must likewise be omitted.The guards check definedness, not truthiness:
false,null, zero, empty strings, and empty collections remain valid values. Regression coverage also verifies fallback behavior and that valid comprehension iterations survive alongside missing values.This is RVM-only. The interpreter, existing set-comprehension runtime filtering, dependencies, and public APIs are unchanged.
Validation
Validated on upstream
mainat32689cb71dd53e8943cbc231f1670c76f41b3273using Rust 1.95.0:cargo +1.95.0 test --quiet --test mod undefined_values -- --nocapturecargo +1.95.0 test --quiet --test mod rvm::rego(45 tests)cargo +1.95.0 fmt --all -- --checkcargo +1.95.0 xtask ci-debuggit diff --checkSeparate language-binding smoke tests were not run.