Skip to content

Attach the receiver's states to state refinement errors - #421

Merged
CatarinaGamboa merged 1 commit into
mainfrom
feat/state-error-context
Oct 24, 2026
Merged

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

Conversation

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator

Why

The VS Code extension shows a state machine with the rejected call highlighted. Today liquidjava-fsm works out the receiver's possible and accepted states again by reading the text of the error's expected and found predicates. The verifier has already computed both with the SMT solver, and the text reading can disagree with it, for example with guarded from clauses, old(...) or several state sets. This PR exposes the verifier's answer, so fsm can go back to only drawing the diagram.

What

StateRefinementError#getContext() returns a StateErrorContext, or null when the states could not be computed:

Field Example
receiver f (as written; this if implicit)
receiverClass testSuite.ErrorStateHintCallSequence
method read() (same format as the hints)
possibleStates [["created"]]
acceptedStates [["open"]], or null when they depend on the arguments
complete whether every method that changes the state is known

Each state lists its name in every state set, in declaration order, e.g. ["closed", "locked"]. The states stay combined because projecting them onto each set separately would mark states as accepted that are not.

To support this, State now keeps its per-set names, and name() still joins them with " and " for the hints. Hints and the category already reach clients through LJDiagnostic.

Tests

TestStateErrorContext covers a single state set, several state sets, a path-dependent state, an argument-dependent transition (accepted states unknown, machine incomplete) and a class without a state set (no context). mvn test: 492 tests pass.

🤖 Generated with Claude Code

StateRefinementError now carries a StateErrorContext with the receiver,
its class, the called method, the states the receiver can be in, the
states that allow the call (per state set) and whether the state machine
is complete, so clients can show the verifier's answer instead of
re-deriving it from the predicates' text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant