@@ -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