Skip to content

Add the failing call's context to StateMachineErrorContext - #9

Merged
CatarinaGamboa merged 1 commit into
mainfrom
feat/7-error-context
Oct 20, 2026
Merged

CatarinaGamboa merged 1 commit into
mainfrom
feat/7-error-context

Conversation

@CatarinaGamboa

Copy link
Copy Markdown
Contributor

Closes #7.

Summary

  • StateMachineErrorContext keeps calledMethod and actualStates and adds receiver, expectedStates, expectedCondition, foundCondition and definiteFoundState. The VS Code State Machine view uses them to focus on a rejected call (Focus the state machine on the rejected call and relevant states vscode-liquidjava#117) and to list state errors (Show state machine errors in the State Machine view vscode-liquidjava#155).
  • Fix: calledMethod was always null for real verifier errors. The verifier reports the position of the @StateRefinement value, not the method, so the exact position comparison never matched. It now selects the smallest method, constructor or static factory whose source range contains that position. Constructors are named after the class.
  • receiver is the source name of the call's receiver (root, not the verifier's instance name).
  • expectedStates lists the states Expected accepts, in state set order: a || b gives [a, b]; !locked gives the other states.
  • expectedCondition and foundCondition are formatted with the verifier's ExpressionFormatter. Found is restricted to premises about the receiver. It is true when nothing is known about the receiver.
  • definiteFoundState is set only when Found has exactly one state call on the receiver as a top-level conjunct and does not negate it. Disjunctions, conditionals, contradictions and negations alone give null.
  • parse(uri) is unchanged. Only callers that construct StateMachineErrorContext directly must pass the new arguments.

Tests

Seven new tests, four of which run the real verifier on new fixtures:

  • DefaultMutableTreeNode: Found childrenAllowed(root), required [maybeHasChildren], calledMethod getFirstChild;
  • a precondition accepting two states;
  • a negated precondition;
  • a Found that does not establish one state (flag ? open(unknown) : closed(unknown)).

The other three construct Expected and Found directly to check the single-Found-state rules and restricting Found to the receiver. They also check method, constructor, static factory and interface-constructor resolution by position. The verifier does not yet report state errors on constructors or factories, so those cases are not exercised through it.

mvn test: 30 tests, all pass.

🤖 Generated with Claude Code

StateMachineErrorContext now also carries the receiver of the failing
call, the states accepted by the Expected condition, the Expected and
Found conditions as readable text (receiver shown by its source name),
and the single state Found establishes for the receiver, if any.

The called method is resolved by checking which method, constructor or
static factory declaration contains the verifier's declaration position
(the position of the state refinement annotation value), instead of
exact position equality, which never matched real verifier errors.

Tests run the verifier on new fixtures, including the
DefaultMutableTreeNode example, a multi-state precondition and a Found
condition that does not establish a single state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CatarinaGamboa
CatarinaGamboa merged commit c6a9e7e into main Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the failing call's context to StateMachineErrorContext

1 participant