|
27 | 27 | import liquidjava.rj_language.ast.formatter.ExpressionFormatter; |
28 | 28 | import spoon.reflect.cu.SourcePosition; |
29 | 29 |
|
30 | | -import static liquidjava.rj_language.opt.VCSimplificationUtils.containsExpression; |
31 | 30 | import static liquidjava.rj_language.opt.VCSimplificationUtils.factsOf; |
32 | 31 | import static liquidjava.rj_language.opt.VCSimplificationUtils.isTrue; |
33 | 32 |
|
@@ -102,19 +101,26 @@ private static Expression withoutGhostDefinitions(Expression refinement, String |
102 | 101 | List<Expression> known = factsOf(error.getFound().getOriginal().getImplication().toPredicate().getExpression()); |
103 | 102 | Expression kept = new LiteralBoolean(true); |
104 | 103 | for (Expression fact : facts) { |
| 104 | + // the ghost on any arguments: an alias of its receiver may be constrained under another name |
105 | 105 | boolean definesGhost = ghostDefined(fact).filter(ghost -> isGhost(ghost.getName(), context)) |
106 | 106 | .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())) |
109 | 109 | .filter(ghost -> known.stream().noneMatch( |
110 | | - other -> containsExpression(other, ghost) && !definesGhostAs(other, ghost, variable))) |
| 110 | + other -> applies(other, ghost.getName()) && !definesGhostAs(other, ghost, variable))) |
111 | 111 | .isPresent(); |
112 | 112 | if (!definesGhost) |
113 | 113 | kept = isTrue(kept) ? fact : new BinaryExpression(kept, "&&", fact); |
114 | 114 | } |
115 | 115 | return kept; |
116 | 116 | } |
117 | 117 |
|
| 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 | + |
118 | 124 | /** Whether {@code name} is a declared ghost, unlike a built-in such as {@code length}, which may be interpreted */ |
119 | 125 | private static boolean isGhost(String name, Context context) { |
120 | 126 | return context.getGhosts().stream().anyMatch(g -> g.matches(name)) |
|
0 commit comments