Skip to content

Commit 1fa001a

Browse files
extract to a function
1 parent 055e933 commit 1fa001a

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

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

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/VCChecker.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,24 +374,45 @@ private boolean hasVariable(Expression exp, String var) {
374374

375375
// Errors---------------------------------------------------------------------------------------------------
376376

377+
/**
378+
* Builds the {@link VCImplication} premise chain that backs an error message. Every refined variable named in
379+
* {@code predicates} — and, transitively, the path variables those drag in — is gathered, and their refinements are
380+
* joined into a chain.
381+
*
382+
* <p>
383+
* Callers pass every predicate that should contribute variables, not just one: a bare predicate such as
384+
* {@code true} carries no variable names and would gather nothing on its own, leaving the chain (and the displayed
385+
* premises) empty. Passing both the {@code found} and {@code expected} refinements ensures the variable that is
386+
* only named on one side still seeds the chain.
387+
*
388+
* @param map
389+
* translation table populated, as a side effect, with the gathered variables' code placements
390+
* @param predicates
391+
* predicates whose variables seed the chain; {@code predicates[0]} is also passed to
392+
* {@code joinPredicates}
393+
*
394+
* @return the joined premise chain
395+
*/
396+
private VCImplication buildPremiseChain(TranslationTable map, Predicate... predicates) {
397+
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
398+
for (Predicate p : predicates) {
399+
gatherVariables(p, lrv, mainVars);
400+
}
401+
return joinPredicates(predicates[0], mainVars, lrv, map);
402+
}
403+
377404
protected void throwRefinementError(SourcePosition position, Predicate expected, Predicate found,
378405
Counterexample counterexample, String customMessage) throws RefinementError {
379-
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
380-
gatherVariables(expected, lrv, mainVars);
381-
gatherVariables(found, lrv, mainVars);
382406
TranslationTable map = new TranslationTable();
383-
Predicate premises = joinPredicates(expected, mainVars, lrv, map).toConjunctions();
407+
Predicate premises = buildPremiseChain(map, expected, found).toConjunctions();
384408
throw new RefinementError(position, expected.simplify(context), premises.simplify(context), map, counterexample,
385409
customMessage);
386410
}
387411

388412
protected void throwStateRefinementError(SourcePosition position, Predicate found, Predicate expected,
389413
String customMessage) throws StateRefinementError {
390-
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
391-
gatherVariables(found, lrv, mainVars);
392-
gatherVariables(expected, lrv, mainVars);
393414
TranslationTable map = new TranslationTable();
394-
VCImplication foundState = joinPredicates(found, mainVars, lrv, map);
415+
VCImplication foundState = buildPremiseChain(map, expected, found);
395416
throw new StateRefinementError(position, expected.simplify(context),
396417
foundState.toConjunctions().simplify(context), map, customMessage);
397418
}
@@ -402,10 +423,8 @@ protected void throwStateConflictError(SourcePosition position, Predicate expect
402423
}
403424

404425
private TranslationTable createMap(Predicate expectedType) {
405-
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
406-
gatherVariables(expectedType, lrv, mainVars);
407426
TranslationTable map = new TranslationTable();
408-
joinPredicates(expectedType, mainVars, lrv, map);
427+
buildPremiseChain(map, expectedType);
409428
return map;
410429
}
411430

0 commit comments

Comments
 (0)