Skip to content

Commit 51a2e6b

Browse files
Keep the names state1, state2, ... for state sets without a name
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3145744 commit 51a2e6b

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎liquidjava-example/src/main/java/testSuite/ErrorStateSetNames.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import liquidjava.specification.RefinementPredicate;
55
import liquidjava.specification.StateSet;
66

7-
// A state set name must be a lowercase identifier that no state, ghost or other state set of the class uses
7+
// A state set name must be a lowercase identifier that no state, ghost or other state set of the class uses, and
8+
// not one of the names given to state sets without a name
89
@StateSet(name = "Door", value = {"closed", "opened"}) // Expect: Error
910
public class ErrorStateSetNames {}
1011

@@ -23,3 +24,6 @@ class ErrorStateSetNameOfAnotherSet {}
2324
@StateSet(name = "size", value = {"empty", "full"}) // Expect: Error
2425
@RefinementPredicate("int size(ErrorStateSetNameOfARefinementPredicate b)")
2526
class ErrorStateSetNameOfARefinementPredicate {}
27+
28+
@StateSet(name = "state2", value = {"closed", "opened"}) // Expect: Error
29+
class ErrorStateSetNameOfAGeneratedName {}

‎liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ private static String stateSetName(CtExpression<?> nameValue, SourcePosition pos
263263
if (!name.matches("[a-z][a-zA-Z0-9_]*") || name.equals(Keys.OLD) || name.equals("true") || name.equals("false"))
264264
throw new CustomError(String.format(
265265
"State set name '%s' must be an identifier that starts with a lowercase letter", name), position);
266+
if (name.matches(Formats.STATE_SET_NAMES))
267+
throw new CustomError(String.format("State set name '%s' is kept for state sets without a name", name),
268+
position);
266269
return name;
267270
}
268271

‎liquidjava-verifier/src/main/java/liquidjava/rj_language/StateValues.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
*/
2626
public final class StateValues {
2727

28-
/** A name {@link Formats#STATE_SET} generates */
29-
private static final String GENERATED_SET_NAME = "state\\d+";
30-
3128
private final List<GhostState> states;
3229
private final Predicate<String> isVariable;
3330
private final Function<Expression, Optional<Predicate<GhostFunction>>> setsFor;
@@ -126,7 +123,7 @@ private static Optional<BinaryExpression> setValue(Expression e, String op, List
126123
return Optional.empty();
127124
List<String> setNames = states.stream().filter(s -> s.getParent() != null && s.matches(invocation.getName()))
128125
.map(s -> s.getParent().getName()).distinct().toList();
129-
if (setNames.size() != 1 || setNames.get(0).matches(GENERATED_SET_NAME))
126+
if (setNames.size() != 1 || setNames.get(0).matches(Formats.STATE_SET_NAMES))
130127
return Optional.empty();
131128
FunctionInvocation set = new FunctionInvocation(qualifiedLike(invocation.getName(), setNames.get(0)),
132129
List.of(invocation.getArgs().get(0).clone()));

‎liquidjava-verifier/src/main/java/liquidjava/utils/constants/Formats.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public final class Formats {
77
public static final String ENUM = "%s.%s";
88
/** The name of a state set declared without one, numbered from 1 in the order of the declarations */
99
public static final String STATE_SET = "state%d";
10+
/** The names {@link #STATE_SET} gives, which a state set cannot be given explicitly */
11+
public static final String STATE_SET_NAMES = "state\\d+";
1012
}

0 commit comments

Comments
 (0)