GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — From note: name an unrefined parameter as the unknown value's origin by CatarinaGamboa · Pull Request #526 · liquid-java/liquidjava

Conversation

@CatarinaGamboa

@CatarinaGamboa CatarinaGamboa commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Closes #522, part 1 of 5: From note F3, unrefined parameter. Design: #522 (comment)

A refinement error whose Expected says nothing the verifier knows now gets a message note naming the cause, when the value is an unrefined parameter of the enclosing method. The CLI prints the note under the headline. getMessageNotes() carries it to the extension, which is meant to show it in the hover (vscode-liquidjava#188).

When the note is printed

All of these must hold, or there is no note:

  • the category is UNKNOWN;
  • every variable of Expected is a parameter of the enclosing method or constructor, by name. A reassigned parameter has an instance, which Expected would name instead;
  • each such parameter's context Variable has the declared refinement true.

The note restates the declaration. It says nothing about callers and adds no fact to Found.

A2_04, before and after (only study task that changes)

 Refinement Error: expected timeout >= 0 but could not prove it
+  From: timeout is a parameter of checkCimReachable(String, int) (line 94) with no refinement
 103 |
 104 |         try (Socket socket = new Socket()) {
 105 |             socket.connect(new InetSocketAddress(host, port), timeout);

A2_10, A1_38, A1_01, A1_56, A1_09, practice and practice2 are byte-identical to main. Each task still gives exactly one error, on its reportedLine.

Changes

  • LJDiagnostic.addMessageNote: getMessageNotes() returns these notes, and RefinementError puts them after its alias where lines. This is the hook the later From PRs use.
  • FromNotes.unrefinedParameters, called where VCChecker builds the refinement error.
  • Test: TestFromNotes on the existing fixture ErrorUnknownArgument.java. It fails without the change.

Conflicts

  • May conflict with One headline frame: found … but expected … for refinement errors #520/Drop the general UNKNOWN hint and show every from in declared-here #521 (another agent: headline and general hint in RefinementError). The overlap is only the getMessageNotes override, and it is a trivial rebase.
  • The later parts of Say where the wrong state or value comes from (From note), and counterexamples for state errors #522 (F1/F2, F4) stack on this branch.

Tests: mvn test, 729 run, 0 failures.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
CatarinaGamboa and others added 2 commits November 10, 2026 15:21
@CatarinaGamboa @claude
Say that an unrefined parameter is where an unknown value comes from
7d5fa12
A refinement error whose Expected is only about parameters of the
enclosing method that are declared with no refinement now has the
message note "From: <p> is a parameter of <m>(<types>) (line L) with no
refinement". It restates the declaration and says nothing about callers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CatarinaGamboa @claude
Leave out the From note for an annotated or externally refined parameter
eb81c8a
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CatarinaGamboa

CatarinaGamboa commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Codex review, round 1

codex exec review --base origin/main: "I found no actionable bugs in the diff."

Custom prompt asking for soundness counterexamples (programs where the note is printed but false). It found two:

  1. An external spec refines the parameter. @ExternalRefinementsFor("LJExternFirst") interface … { void use(@Refinement("_ > 0") int amount); } printed From: amount is a parameter of use(int) (line 8) with no refinement. The verifier does not check the body against that spec, but "with no refinement" is false.
  2. Explicit @Refinement("true") on the parameter. The note said "with no refinement".

Fixed (both), in b-commit "Leave out the From note for an annotated or externally refined parameter". There is no note when:

  • the parameter carries any @Refinement annotation, or
  • a context function for the same method (class, name, arity) refines that parameter.

Both programs now print no note. Tests: 729 run, 0 failures.

No regression test added. Each case would need a new fixture file, and the PM asked for lean tests. I'll add them if wanted.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CatarinaGamboa

CatarinaGamboa commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Clean-code review

I audited the diff with the clean-code-principles checklist.

Fixed:

  • FromNotes.java - [core-fail-fast] A parameter without a valid source position would have printed (line -1). Now there is no note.
  • FromNotes.java - [solid-srp] The "is the parameter refined anywhere" check is its own method (isRefined), apart from building the note text.

Declined:

  • [pattern-strategy] An interface for the kinds of From note. There is one kind here, and the later PRs add one function each. That would be YAGNI for this PR.
  • [func-few-arguments] unrefinedParameters(error, checked, context) keeps three arguments. Bundling them would add a type for one call site.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CatarinaGamboa @claude
Match a parameter's specification by its method's parameter types
3c89e39
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CatarinaGamboa

CatarinaGamboa commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Codex review, round 2

codex exec review:

[P2] Match the exact overload before suppressing a parameter note. With two same-arity overloads, a refinement on one overload's parameter suppresses the note for an unrefined parameter of the other.

Fixed in "Match a parameter's specification by its method's parameter types". isRefined now compares the qualified parameter types too.

  • Check: void use(int amount) { take(amount); } next to void use(@Refinement("_ != 0") long amount) {} prints the note for use(int) again.
  • The round 1 cases (external spec, @Refinement("true")) still print no note.

Tests: 729 run, 0 failures.

Custom soundness prompt: stopped by Codex's content filter partway through, with no findings. I'll rephrase it in round 3.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CatarinaGamboa

CatarinaGamboa commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Codex review, round 3

codex exec review: "I found no actionable regressions in the changes."

Soundness prompt (rephrased, so the content filter let it through). It tried inner, anonymous and local classes, lambdas, constructors, records, varargs, generics and inherited specs. It found no case where the note names the wrong parameter, method or line, or calls a refined parameter unrefined. It reported two formatting differences:

  • use(List<String> names, int n) is shown as use(List, int);
  • use(int n, String... labels) is shown as use(int, String[]).

Declined, both. The signature is written the way the state hints already write methods (StateHints.parameters: CtTypeReference::getSimpleName, so read(byte[], int, int)). One convention across the messages beats Java source syntax in one note. Neither form states anything false.

This ends the Codex loop for this PR: nothing relevant is left.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 10, 2026
Show a counterexample for state errors, restricted to the shown Found #527
Closed
Origin note: say where the wrong state of a receiver comes from #528
Merged
Origin note: say what a call's return refinement guarantees about an argument it gives #530
Merged
Say where the wrong state or value comes from (From note), and counterexamples for state errors #522
Closed
@CatarinaGamboa
CatarinaGamboa merged commit 920bf15 into main Nov 10, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@CatarinaGamboa CatarinaGamboa mentioned this pull request Nov 10, 2026
Mark code in every message with backticks: blue in the CLI, code font in the IDE #532
Closed
CatarinaGamboa added a commit that referenced this pull request Nov 11, 2026
@CatarinaGamboa @claude
Origin note: say where the wrong state of a receiver comes from (#528)
070fb75
Closes #522, part 2: **origin notes F1 and F2**, where the wrong state
comes from. Design:
#522 (comment)

**Base: `main`.** #526 is merged. #530 is stacked on this PR, so
retarget it to `main` before merging this one with `--delete-branch`.

## The Origin note
The PM's review renamed the note from **"From:"** to **"Origin:"**,
because "From" read like `@StateRefinement(from = …)` in declared-here.
Every origin note now has one shape, `Origin: <where>, <call or
variable> <verb> <state or refinement>`, and only the verb changes. The
first commit renames the note #526 merged (`FromNotes` → `OriginNotes`,
`TestFromNotes` → `TestOriginNotes`). The soundness conditions are
unchanged.

| Case | Text |
|---|---|
| F1, the call that last set the sets | `Origin: line 134, new
BufferedInputStream(stream) makes markState(buffered) == unmarked` |
| F2, a returned value | `Origin: line 130,
writer.getDefaultWriteParam() returns compression(wParam) ==
compressionNotExplicit` |
| F2, nothing known | `Origin: line 69, frame.getUndoManager() says
nothing about redoState(undoManager)` |
| F1 fallback, creation | `Origin: line L, new T(…) creates x with
<state>` |
| F3 (#526) | `Origin: line 94, timeout is a parameter of
checkCimReachable(String, int) with no refinement` |

"Makes" is used only for the call the walk proves last set the shown
sets. The fallback says "creates … with", because a later call may have
set the state again. That is a fact about the constructor, not about the
current state.

## When there is no note at all
No origin note is given when the receiver may change state out of the
verifier's sight before the call. That covers three cases:
- **Another name may hold it.** A local, a parameter or `this` is used,
before the call, other than as the target of a call or field access or
in `==`/`!=`. That means copied, passed as an argument (including to the
failing call itself), stored in an array, returned, bound in a method
reference (`x::start`), or used in a lambda or a local class. "Before"
means earlier in the source, in the failing call's arguments, or in a
loop around the call, unless the use is inside a `return`/`throw`.
- **A method of the analyzed code with no state refinement is called on
it before.** The verifier assumes such a call keeps the state.
- **It is a field.**

Declared state contracts are trusted, as the verifier trusts them. A
body that breaks its own declared contract is a verifier issue, outside
the notes (see the round 3 reply).

## Which sets
The note covers the sets that the failing call's `from` checks. When the
state machine models the call, it narrows them to the sets where some
state the receiver may be in is the state of no allowed state. This only
selects what is shown (S1).

## F1, a state set by a call
Walk back from the receiver through `StateChange`/`previous()` to the
first change whose `to` names a shown set. The note is printed only if:
- every instance on the way has a `StateChange`, so the walk crosses no
join, loop head or unknown origin;
- every change crossed names none of the shown sets. Each `to` keeps the
sets it does not name, through `set(this) == set(old(this))`;
- `StateSolver.implies(<instance after that change>, <Found's facts on
the shown sets>)` holds.

Text: `Origin: line L, <call> makes <Found on the sets that change
names>`. With two wrong sets, a change to one is not given the other.

**Fallback, when the walk breaks.** The note gives the creation fact
only if all hold:
- the receiver is a local whose only write is its initializer, a
constructor call with a single state refinement;
- no other call on it is to a method that changes state, and no loop may
repeat the failing call;
- Found's facts on the shown sets imply what that constructor gives.

Text: `Origin: line L, new T(…) creates x with <state>`. It is a fact
about the constructor. The last condition stops it from speaking when
the state may have changed since (A1_09).

## F2, a state from a returned value
Printed only if the walk reaches, possibly after crossing changes to
other sets, an instance with no `StateChange` that holds the call result
it was assigned. Instances now record a `CallResult` when a local is
declared or assigned from a call to a refined method. A state-preserving
call keeps it, as it keeps the `StateChange`. Joins, loop heads and
transitions make new instances without one.
- `Origin: line L, <call> returns <facts>`: the conjuncts of the
instantiated return refinement on the shown sets. Printed only if they
imply Found's facts on those sets.
- `Origin: line L, <call> says nothing about <set>(x)`: printed only if
all hold:
  - Found has no fact on the sets;
- the method has no state refinement with a `to` (as `to =
"running(_)"`);
- the return refinement names no state of them, mentions no variable but
`_`, and uses no alias. This rules out `_ == this`-style returns;
- no shown set has a generated name (`state1`), which the message would
otherwise never show.

## DebugLog check for A1_38 (asked before coding F1)
With `-d`, the VC at `buffered.reset()` (line 157) has a single
`buffered` instance, `#buffered_259 : (stream == open) ∧ (markState ==
unmarked)`. That is the constructor's state, with no ITE and no
loop-head instance. The note also took the F1 path, which needs a
`StateChange` on that instance. So neither loop (lines 136 and 150)
creates a join for `buffered`.

A broken walk now logs `[WARN] Origin note: no known call gives #x_n its
state, e.g. a join of branches`. A1_09 logs it for `#host_95`.

## Study tasks, before (main) and after
```diff
 State Refinement Error: found stream(buffered) == open && markState(buffered) == unmarked but expected markState(buffered) == marked && stream(buffered) == open
+  Origin: line 134, new BufferedInputStream(stream) makes markState(buffered) == unmarked
```
```diff
 State Refinement Error: found compression(wParam) == compressionNotExplicit but expected compression(wParam) == compressionExplicit || compression(wParam) == compressionTypeSet
+  Origin: line 130, writer.getDefaultWriteParam() returns compression(wParam) == compressionNotExplicit
```
```diff
 State Refinement Error: expected redoState(undoManager) == redoable but could not prove it
+  Origin: line 69, frame.getUndoManager() says nothing about redoState(undoManager)
```
```diff
 Refinement Error: expected timeout >= 0 but could not prove it
-  From: timeout is a parameter of checkCimReachable(String, int) (line 94) with no refinement
+  Origin: line 94, timeout is a parameter of checkCimReachable(String, int) with no refinement
```
- A1_09: no origin note. Its receiver is a join, and Found does not say
the state `new JFrame(…)` gives.
- A2_10, practice and practice2: unchanged.

Each task still gives exactly one error, on its `reportedLine`. All
three notes are the review's mock-ups, word for word.

I checked every state-error fixture of the suite. Each note names the
creating or the last call. After the Codex rounds, the fallback fires in
none, and fixtures where the receiver is captured, a field, `this` in a
loop, or given an unspecified call get no note.

## Tests
`TestOriginNotes`, three tests that fail without the change:
- `ErrorStateHintMultipleSets` (existing): `Origin: line 27, d.lock()
makes lockState(d) == locked`. Only the wrong set is named, and the walk
stops at the change to it;
- `ErrorStateFromReturnedValue` (new, small; no existing fixture assigns
a state from a return refinement): `Origin: line 27,
FromReturnedTask.create() returns phase(task) == idle`.

- `ErrorDeferredCallbackState` (existing): the receiver captured by a
lambda gets no note.

`mvn test`: 736 run, 0 failures.

## Conflicts
- With #520/#521 (another agent: `AuxStateHandler` declared-here): the
one `throwStateRefinementError` call in `changeState`, which gets a
`messageNotes` argument. The rest is additive.
- With #518/#519 (`StateHints`): none.
- With #527 (state counterexample, mine): both add a parameter to
`throwStateRefinementError`, a one-line rebase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Say where the wrong state or value comes from (From note), and counterexamples for state errors

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@CatarinaGamboa
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.