Skip to content

Commit 5ec95ec

Browse files
committed
Refactor Counterexamples
1 parent 16070e0 commit 5ec95ec

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import liquidjava.rj_language.ast.formatter.VariableFormatter;
1111
import liquidjava.rj_language.opt.VCSimplificationResult;
1212
import liquidjava.smt.Counterexample;
13+
import liquidjava.utils.Pair;
1314
import spoon.reflect.cu.SourcePosition;
1415

1516
/**
@@ -32,30 +33,42 @@ public RefinementError(SourcePosition position, Predicate expected, VCSimplifica
3233
position, translationTable, customMessage);
3334
this.expected = expected;
3435
this.found = found;
35-
this.counterexample = counterexample;
36+
this.counterexample = filterCounterexample(counterexample);
3637
}
3738

3839
@Override
3940
public String getDetails() {
40-
Counterexample counterexamples = getCounterExamples();
41-
if (counterexamples == null)
41+
if (counterexample == null)
4242
return "";
4343

44-
String counterexampleString = counterexamples.assignments().stream()
44+
String counterexampleString = counterexample.assignments().stream()
4545
.map(a -> VariableFormatter.format(a.first()) + " == " + a.second())
4646
.collect(Collectors.joining(" && "));
4747
return "Counterexample: " + counterexampleString;
4848
}
4949

50+
public Counterexample getCounterexample() {
51+
return counterexample;
52+
}
53+
54+
public Predicate getExpected() {
55+
return expected;
56+
}
57+
58+
public VCSimplificationResult getFound() {
59+
return found;
60+
}
61+
5062
// Filters counterexample assignments only in found VC and sorts them in the order of its binders
51-
public Counterexample getCounterExamples() {
63+
private Counterexample filterCounterexample(Counterexample counterexample) {
5264
if (counterexample == null || counterexample.assignments().isEmpty())
5365
return null;
5466

5567
List<String> binderNames = getFound().getBinders();
5668
Set<String> knownAssignments = getFound().getImplication().toPredicate().getExpression().getConjuncts().stream()
5769
.map(Expression::toString).collect(Collectors.toSet());
58-
var assignments = counterexample.assignments().stream().filter(a -> binderNames.contains(a.first()))
70+
List<Pair<String, String>> assignments = counterexample.assignments().stream()
71+
.filter(a -> binderNames.contains(a.first()))
5972
.filter(a -> !knownAssignments.contains(a.first() + " == " + a.second()))
6073
.sorted((a, b) -> Integer.compare(binderNames.indexOf(a.first()), binderNames.indexOf(b.first())))
6174
.toList();
@@ -65,16 +78,4 @@ public Counterexample getCounterExamples() {
6578

6679
return new Counterexample(assignments);
6780
}
68-
69-
public Counterexample getCounterexample() {
70-
return counterexample;
71-
}
72-
73-
public Predicate getExpected() {
74-
return expected;
75-
}
76-
77-
public VCSimplificationResult getFound() {
78-
return found;
79-
}
8081
}

0 commit comments

Comments
 (0)