Skip to content

Commit 12366b4

Browse files
Keep a ghost definition when the ghost is applied anywhere else
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 330264d commit 12366b4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import liquidjava.rj_language.ast.formatter.ExpressionFormatter;
2828
import spoon.reflect.cu.SourcePosition;
2929

30-
import static liquidjava.rj_language.opt.VCSimplificationUtils.containsExpression;
3130
import static liquidjava.rj_language.opt.VCSimplificationUtils.factsOf;
3231
import static liquidjava.rj_language.opt.VCSimplificationUtils.isTrue;
3332

@@ -102,19 +101,26 @@ private static Expression withoutGhostDefinitions(Expression refinement, String
102101
List<Expression> known = factsOf(error.getFound().getOriginal().getImplication().toPredicate().getExpression());
103102
Expression kept = new LiteralBoolean(true);
104103
for (Expression fact : facts) {
104+
// the ghost on any arguments: an alias of its receiver may be constrained under another name
105105
boolean definesGhost = ghostDefined(fact).filter(ghost -> isGhost(ghost.getName(), context))
106106
.filter(ghost -> facts.stream()
107-
.noneMatch(other -> other != fact && containsExpression(other, ghost)))
108-
.filter(ghost -> !containsExpression(error.getExpected().getExpression(), ghost))
107+
.noneMatch(other -> other != fact && applies(other, ghost.getName())))
108+
.filter(ghost -> !applies(error.getExpected().getExpression(), ghost.getName()))
109109
.filter(ghost -> known.stream().noneMatch(
110-
other -> containsExpression(other, ghost) && !definesGhostAs(other, ghost, variable)))
110+
other -> applies(other, ghost.getName()) && !definesGhostAs(other, ghost, variable)))
111111
.isPresent();
112112
if (!definesGhost)
113113
kept = isTrue(kept) ? fact : new BinaryExpression(kept, "&&", fact);
114114
}
115115
return kept;
116116
}
117117

118+
/** Whether {@code expression} applies the function {@code name}, to any arguments */
119+
private static boolean applies(Expression expression, String name) {
120+
return expression instanceof FunctionInvocation invocation && invocation.getName().equals(name)
121+
|| expression.getChildren().stream().anyMatch(child -> applies(child, name));
122+
}
123+
118124
/** Whether {@code name} is a declared ghost, unlike a built-in such as {@code length}, which may be interpreted */
119125
private static boolean isGhost(String name, Context context) {
120126
return context.getGhosts().stream().anyMatch(g -> g.matches(name))

0 commit comments

Comments
 (0)