Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions part4/exercises-add-refinements/src/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import repair.regen.specification.StateRefinement;
import repair.regen.specification.StateSet;

@StateSet({"notready", "ready", "finished"})
public class Iterator {
boolean hn;

@StateRefinement(from = "notready(this)", to = "ready(this)")
boolean hasNext(boolean hn) { return hn; }

@StateRefinement(from = "ready(this)", to = "finished(this)")
int next(boolean hn) {
if (hn) {
return 1;
} else {
return -1;
}
}
}
9 changes: 9 additions & 0 deletions part4/exercises-add-refinements/src/IteratorWrong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class IteratorWrong {
public static void main() {
Iterator i = new Iterator(); // i -> "notready"
boolean hn = true;
// i.next() requires state "ready" but i is "notready"
int x = i.next(hn); // shouldn't be accepted by the typechecker ;-;
}
}