Skip to content

Commit 6a562cb

Browse files
Document named state sets and states written as values of their sets
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9d8ccad commit 6a562cb

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎README.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ LiquidJava also supports object state modeling via typestates, which allows enfo
3737

3838
```java
3939
@ExternalRefinementsFor("java.net.Socket")
40-
@StateSet({"unconnected", "bound", "connected", "closed"})
40+
@StateSet(name="connection", value={"unconnected", "bound", "connected", "closed"})
4141
public interface SocketRefinements {
42-
@StateRefinement(to="unconnected(this)")
42+
@StateRefinement(to="connection(this) == unconnected")
4343
public void Socket();
4444

45-
@StateRefinement(from="unconnected(this)", to="bound(this)")
45+
@StateRefinement(from="connection(this) == unconnected", to="connection(this) == bound")
4646
public void bind(SocketAddress add);
4747

48-
@StateRefinement(from="bound(this)", to="connected(this)")
48+
@StateRefinement(from="connection(this) == bound", to="connection(this) == connected")
4949
public void connect(SocketAddress add);
5050

51-
@StateRefinement(from="connected(this)")
51+
@StateRefinement(from="connection(this) == connected")
5252
public void sendUrgentData(int n);
5353

54-
@StateRefinement(from="!closed(this)", to="closed(this)")
54+
@StateRefinement(from="connection(this) != closed", to="connection(this) == closed")
5555
public void close();
5656
}
5757

@@ -61,6 +61,12 @@ socket.sendUrgentData(1); // State Refinement Error
6161
socket.close();
6262
```
6363

64+
A state set can be given a `name`, and a state is then written as a value of its set, `connection(this) == bound`. The shorter form `bound(this)` means the same and is also accepted. A class can have several state sets; a method's `to` keeps unchanged the sets it does not mention. Error messages show the states of named sets in the first form, so they say which set is in which state:
65+
66+
```
67+
State Refinement Error: found connection(socket) == bound but expected connection(socket) == connected
68+
```
69+
6470
Lambda bodies are checked separately from the code that creates them. Creating a lambda does not apply its state
6571
transitions to captured objects. While checking the body, LiquidJava keeps declared refinements but forgets the current
6672
state of mutable captures, since that state may change before invocation. Callback execution summaries are not supported:

0 commit comments

Comments
 (0)