Conversation
…wing Fixes informalsystems#1820 ## Problem When a nondet binding has the same name as a state variable, assignments to that variable fail with QNT502 "Variable not set": ```quint module foo { var bar: int action init = { nondet bar = Nat.oneOf() // shadows state var 'bar' bar' = bar // QNT502: Variable bar not set } } ``` The error occurred because the name resolver treated assignment LHS (`bar'`) like any other name reference, resolving it to the most recent definition in scope - the nondet binding instead of the state variable. Since the nondet binding isn't a state variable, the runtime couldn't find a var to update. ## Root Cause In Quint, the assignment operator `bar' = expr` has special semantics: - LHS (`bar`) must always refer to a state variable declaration - RHS (`expr`) follows normal scoping rules and can reference shadowing bindings The resolver wasn't distinguishing between these two contexts, applying standard name resolution to both sides. ## Solution Introduce special handling for assignment LHS in the name resolver: 1. In `enterApp()`, detect `assign` applications and record the LHS name's ID 2. In `enterName()`, check if the name is an assignment LHS 3. If so, use `resolveAssignmentTarget()` which searches for a `var` definition with that name, bypassing any shadowing non-var definitions 4. RHS continues to use standard resolution, correctly picking up shadows This ensures `bar' = bar` in the example above resolves: - LHS `bar` → state variable declaration - RHS `bar` → nondet binding (the shadowing definition) ## Changes - **quint/src/names/resolver.ts**: Add `assignLhsIds` tracking and `resolveAssignmentTarget()` method for special LHS handling - **quint/test/names/resolver.test.ts**: Add regression tests verifying: - All assignment LHS resolve to state vars when shadowed - Assignment RHS correctly resolves to shadowing binding ## Testing - Added unit tests that reproduce the exact issue from informalsystems#1820 - Verified both LHS (state var) and RHS (shadow) resolve correctly - Ran existing test suite to ensure no regressions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
(including screenshots is helpful)
CHANGELOG.mdfor any new functionality