Skip to content

Commit 5c838bd

Browse files
Share the declaration of a local variable without value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 109dfd0 commit 5c838bd

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,7 @@ public <T> void visitCtLocalVariable(CtLocalVariable<T> localVariable) {
207207
super.visitCtLocalVariable(localVariable);
208208
// only declaration, no assignment
209209
if (localVariable.getAssignment() == null) {
210-
Optional<Predicate> a = getRefinementFromAnnotation(localVariable);
211-
RefinedVariable v = context.addVarToContext(localVariable.getSimpleName(), localVariable.getType(),
212-
a.orElse(new Predicate()), localVariable);
213-
getMessageFromAnnotation(localVariable).ifPresent(v::setMessage);
210+
declareWithoutValue(localVariable);
214211
} else {
215212
String varName = localVariable.getSimpleName();
216213
CtExpression<?> e = localVariable.getAssignment();
@@ -226,6 +223,14 @@ public <T> void visitCtLocalVariable(CtLocalVariable<T> localVariable) {
226223
}
227224
}
228225

226+
/** Adds a local variable to the context with only its declared refinement */
227+
private void declareWithoutValue(CtLocalVariable<?> localVariable) {
228+
Optional<Predicate> a = getRefinementFromAnnotation(localVariable);
229+
RefinedVariable v = context.addVarToContext(localVariable.getSimpleName(), localVariable.getType(),
230+
a.orElse(new Predicate()), localVariable);
231+
getMessageFromAnnotation(localVariable).ifPresent(v::setMessage);
232+
}
233+
229234
/** Records on the new instance of a local variable the call whose value it was assigned, if any */
230235
private void recordReturnedValue(String name, CtExpression<?> value) {
231236
if (value != null && value.getMetadata(Keys.CALL_RESULT)instanceof CallResult result)
@@ -1147,8 +1152,7 @@ private void skip(CtStatement statement) {
11471152
for (String name : changedIn(statement, statement))
11481153
forgetChanges(name, new Predicate(), statement);
11491154
if (statement instanceof CtLocalVariable<?> localVariable)
1150-
context.addVarToContext(localVariable.getSimpleName(), localVariable.getType(),
1151-
getRefinementFromAnnotation(localVariable).orElse(new Predicate()), localVariable);
1155+
declareWithoutValue(localVariable);
11521156
}
11531157

11541158
/** Checks the body of a loop, up to the point after it where its continues join */

0 commit comments

Comments
 (0)