Skip to content

Commit 58349fa

Browse files
StateRefinementError was now shows all needed variables (#232)
## Description `StateRefinementError` was not showing error message with all the needed variables. Error example: ``` [SMT] #body_9 : BufferedInputStream true [SMT] #fresh_11 : boolean (#fresh_11 == true --> state1(#body_9) == 1) ∧ (#fresh_11 == false) [SMT] ──────────────────────────────────────── [SMT] state1(#body_9) == 2 [SMP] Before simplification: true [SMP] After simplification: true ``` ## Example Now we do the same as for the `RefinementError`, gathering variables also from the expected. Result: ``` [SMP] Before simplification: [SMP] #fresh_11 == true --> markSupported(#body_9) && [SMP] #fresh_11 == false [SMP] After simplification: false --> markSupported(#body_9) ``` ## Type of change - [x] Bug fix - [ ] New feature - [ ] Documentation update - [ ] Code refactoring ## Checklist - [ ] Added/updated tests under `liquidjava-example/src/main/java/testSuite/` (`Correct*` / `Error*`) - [x] `mvn test` passes locally - [ ] Updated docs/README if behavior or API changed
1 parent 8805dab commit 58349fa

1 file changed

Lines changed: 30 additions & 10 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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,23 +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);
392414
TranslationTable map = new TranslationTable();
393-
VCImplication foundState = joinPredicates(found, mainVars, lrv, map);
415+
VCImplication foundState = buildPremiseChain(map, expected, found);
394416
throw new StateRefinementError(position, expected.simplify(context),
395417
foundState.toConjunctions().simplify(context), map, customMessage);
396418
}
@@ -401,10 +423,8 @@ protected void throwStateConflictError(SourcePosition position, Predicate expect
401423
}
402424

403425
private TranslationTable createMap(Predicate expectedType) {
404-
List<RefinedVariable> lrv = new ArrayList<>(), mainVars = new ArrayList<>();
405-
gatherVariables(expectedType, lrv, mainVars);
406426
TranslationTable map = new TranslationTable();
407-
joinPredicates(expectedType, mainVars, lrv, map);
427+
buildPremiseChain(map, expectedType);
408428
return map;
409429
}
410430

0 commit comments

Comments
 (0)