Skip to content

Commit 2fa8e6e

Browse files
Name states briefly in every state hint, and tell a failed check from an unknown state
- Name a set of states as the fewest groups that each fix the state in some state sets, so open(this) || loud(this) reads "open or loud" and a partly known state is named in its known state sets only. Every state hint uses this, for the current, needed and reached states. - Only call a state unknown when nothing mentions it. When it is mentioned only through another value, such as the result of an earlier check, say that what is known does not decide it. - Always name the needed state and the constructors, even when every state allows the call by a different state refinement. - Do not suggest creating a new object when the receiver is this. - Rename the hint kind REACHING_CALLS to NEEDED_STATE, and share the call sequence search between known and unknown states. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a9a1dd8 commit 2fa8e6e

21 files changed

Lines changed: 531 additions & 109 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// Only one of three state sets is known (notRedoable), so the hints name that set only
7+
@StateSet({"start", "canEdit", "end"})
8+
@StateSet({"undoable", "notUndoable"})
9+
@StateSet({"redoable", "notRedoable"})
10+
public class ErrorStateHintPartlyKnown {
11+
12+
@StateRefinement(to = "start(this) && notUndoable(this) && notRedoable(this)")
13+
public ErrorStateHintPartlyKnown() {}
14+
15+
@StateRefinement(from = "redoable(this)", to = "undoable(this) && notRedoable(this)")
16+
public void redo() {}
17+
18+
@StateRefinement(from = "undoable(this)", to = "notUndoable(this) && redoable(this)")
19+
public void undo() {}
20+
21+
@StateRefinement(from = "notRedoable(this)")
22+
public void check() {
23+
this.redo(); // Expect: State Refinement Error
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// read() accepts a state of either set, so each is named alone, not combined with every state of the other set
7+
@StateSet({"created", "open", "ready"})
8+
@StateSet({"quiet", "loud"})
9+
public class ErrorStateHintUnknownCrossDisjunction {
10+
11+
@StateRefinement(to = "created(this) && quiet(this)")
12+
public ErrorStateHintUnknownCrossDisjunction() {}
13+
14+
@StateRefinement(from = "open(this) || loud(this)")
15+
public void read() {}
16+
17+
public static void use(ErrorStateHintUnknownCrossDisjunction s) {
18+
s.read(); // Expect: State Refinement Error
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// From any state, go() needs four calls (reset, a, b, c), more than a hint suggests
7+
@StateSet({"s0", "s1", "s2", "s3"})
8+
public class ErrorStateHintUnknownLongPath {
9+
10+
@StateRefinement(to = "s0(this)")
11+
public ErrorStateHintUnknownLongPath() {}
12+
13+
@StateRefinement(to = "s0(this)")
14+
public void reset() {}
15+
16+
@StateRefinement(from = "s0(this)", to = "s1(this)")
17+
public void a() {}
18+
19+
@StateRefinement(from = "s1(this)", to = "s2(this)")
20+
public void b() {}
21+
22+
@StateRefinement(from = "s2(this)", to = "s3(this)")
23+
public void c() {}
24+
25+
@StateRefinement(from = "s3(this)")
26+
public void go() {}
27+
28+
public static void use(ErrorStateHintUnknownLongPath x) {
29+
x.go(); // Expect: State Refinement Error
30+
}
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// go() accepts s1 or s2, and a different call reaches each of them from any state
7+
@StateSet({"s0", "s1", "s2", "s3"})
8+
public class ErrorStateHintUnknownSeveralWays {
9+
10+
@StateRefinement(to = "s0(this)")
11+
public ErrorStateHintUnknownSeveralWays() {}
12+
13+
@StateRefinement(to = "s1(this)")
14+
public void one() {}
15+
16+
@StateRefinement(to = "s2(this)")
17+
public void two() {}
18+
19+
@StateRefinement(to = "s3(this)")
20+
public void three() {}
21+
22+
@StateRefinement(from = "s1(this) || s2(this)")
23+
public void go() {}
24+
25+
public static void use(ErrorStateHintUnknownSeveralWays x) {
26+
x.go(); // Expect: State Refinement Error
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// The receiver is this, so creating a new object, though it would start in open, is not suggested
7+
@StateSet({"open", "closed"})
8+
public class ErrorStateHintUnknownThis {
9+
10+
@StateRefinement(to = "open(this)")
11+
public ErrorStateHintUnknownThis() {}
12+
13+
@StateRefinement(from = "open(this)")
14+
public void read() {}
15+
16+
@StateRefinement(from = "open(this)", to = "closed(this)")
17+
public void close() {}
18+
19+
public void helper() {
20+
this.read(); // Expect: State Refinement Error
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// flip() is allowed in every state, but by a different state refinement in each, so an unknown state rejects it
7+
@StateSet({"up", "down"})
8+
public class ErrorStateHintUnknownToggle {
9+
10+
@StateRefinement(to = "up(this)")
11+
public ErrorStateHintUnknownToggle() {}
12+
13+
@StateRefinement(from = "up(this)", to = "down(this)")
14+
@StateRefinement(from = "down(this)", to = "up(this)")
15+
public void flip() {}
16+
17+
public static void use(ErrorStateHintUnknownToggle t) {
18+
t.flip(); // Expect: State Refinement Error
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.StateRefinement;
4+
import liquidjava.specification.StateSet;
5+
6+
// Like UndoManager.undoOrRedo(): one state refinement per state set, so the call needs undoable or redoable
7+
@StateSet({"start", "canEdit", "end"})
8+
@StateSet({"undoable", "notUndoable"})
9+
@StateSet({"redoable", "notRedoable"})
10+
public class ErrorStateHintUnknownTwoRefinements {
11+
12+
@StateRefinement(to = "start(this) && notUndoable(this) && notRedoable(this)")
13+
public ErrorStateHintUnknownTwoRefinements() {}
14+
15+
@StateRefinement(from = "undoable(this)", to = "notUndoable(this) && notRedoable(this)")
16+
@StateRefinement(from = "redoable(this)", to = "notUndoable(this) && notRedoable(this)")
17+
public void undoOrRedo() {}
18+
19+
public static void use(ErrorStateHintUnknownTwoRefinements history) {
20+
history.undoOrRedo(); // Expect: State Refinement Error
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package testSuite.classes.state_hint_checked_state_error;
2+
3+
import java.util.Scanner;
4+
5+
// The state was checked and the check failed: the state is not unknown, but the check does not decide it either
6+
public class Reader {
7+
8+
public static void nextWhenThereIsNone(Scanner it) {
9+
if (!it.hasNext()) {
10+
it.next(); // Expect: State Refinement Error
11+
}
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testSuite.classes.state_hint_checked_state_error;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.Refinement;
5+
import liquidjava.specification.StateRefinement;
6+
import liquidjava.specification.StateSet;
7+
8+
@StateSet({"hasMore", "noMore"})
9+
@ExternalRefinementsFor("java.util.Scanner")
10+
public interface ScannerRefinements {
11+
12+
@Refinement("_ == true --> hasMore(this)")
13+
boolean hasNext();
14+
15+
@StateRefinement(from = "hasMore(this)", to = "noMore(this)")
16+
String next();
17+
}

‎liquidjava-verifier/src/main/java/liquidjava/diagnostics/hints/Hint.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ public enum Kind {
2525
PATH_DEPENDENT_STATE,
2626
/** The object is in a state where no call with a state refinement is allowed */
2727
FINAL_STATE,
28-
/**
29-
* The object's state is unknown: the state the failing call needs, and the constructors that create it in one
30-
*/
31-
REACHING_CALLS
28+
/** The object can be in any state: the state the failing call needs, and the constructors that create it */
29+
NEEDED_STATE
3230
}
3331

3432
public static Hint general(String message) {

0 commit comments

Comments
 (0)