Skip to content

Commit 694202b

Browse files
committed
Make Counterexample Filtering Order Insensitive
1 parent c68a166 commit 694202b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

liquidjava-verifier/src/main/java/liquidjava/diagnostics/errors/RefinementError.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.stream.Collectors;
66

77
import liquidjava.diagnostics.TranslationTable;
8+
import liquidjava.rj_language.ast.Expression;
89
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
910
import liquidjava.smt.Counterexample;
1011
import liquidjava.utils.VariableFormatter;
@@ -46,16 +47,17 @@ public String getCounterExampleString() {
4647

4748
List<String> foundVarNames = new ArrayList<>();
4849
found.getValue().getVariableNames(foundVarNames);
50+
List<String> foundAssignments = found.getValue().getConjuncts().stream().map(Expression::toString).toList();
4951
String counterexampleString = counterexample.assignments().stream()
50-
// only include variables that appear in the found value
51-
.filter(a -> foundVarNames.contains(a.first()))
52+
// only include variables that appear in the found value and are not already fixed there
53+
.filter(a -> foundVarNames.contains(a.first())
54+
&& !foundAssignments.contains(a.first() + " == " + a.second()))
5255
// format as "var == value"
5356
.map(a -> VariableFormatter.formatVariable(a.first()) + " == " + a.second())
5457
// join with "&&"
5558
.collect(Collectors.joining(" && "));
5659

57-
String foundString = VariableFormatter.formatText(found.getValue().toString());
58-
if (counterexampleString.isEmpty() || counterexampleString.equals(foundString))
60+
if (counterexampleString.isEmpty())
5961
return null;
6062

6163
return counterexampleString;

liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/Expression.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public boolean isBooleanExpression() {
8181
return false;
8282
}
8383

84+
public List<Expression> getConjuncts() {
85+
if (this instanceof BinaryExpression binaryExpression && "&&".equals(binaryExpression.getOperator())) {
86+
List<Expression> conjuncts = new ArrayList<>();
87+
conjuncts.addAll(binaryExpression.getFirstOperand().getConjuncts());
88+
conjuncts.addAll(binaryExpression.getSecondOperand().getConjuncts());
89+
return conjuncts;
90+
}
91+
return List.of(this);
92+
}
93+
8494
/**
8595
* Substitutes the expression first given expression by the second
8696
*

0 commit comments

Comments
 (0)