@@ -916,7 +916,10 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
916916 // Restore all outer type variables, constraints
917917 // and scoring information.
918918 Snapshot.reset ();
919- restoreOuterState ();
919+
920+ // Restore original scores of outer context before
921+ // trying to produce a combined solution.
922+ restoreOriginalScores ();
920923
921924 // Apply all of the information deduced from the
922925 // conjunction (up to the point of ambiguity)
@@ -925,6 +928,13 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
925928 ConstraintSystem::SolverScope scope (CS);
926929
927930 CS.applySolution (solution);
931+
932+ // `applySolution` changes best/current scores
933+ // of the constraint system, so they have to be
934+ // restored right afterwards because score of the
935+ // element does contribute to the overall score.
936+ restoreOriginalScores ();
937+
928938 // Note that `worseThanBestSolution` isn't checked
929939 // here because `Solutions` were pre-filtered, and
930940 // outer score is the same for all of them.
@@ -953,9 +963,9 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
953963}
954964
955965void ConjunctionStep::restoreOuterState () const {
956- // Restore best score, since upcoming step is going to
966+ // Restore best/current score, since upcoming step is going to
957967 // work with outer scope in relation to the conjunction.
958- CS. solverState -> BestScore = BestScore ;
968+ restoreOriginalScores () ;
959969
960970 // Active all of the previously out-of-scope constraints
961971 // because conjunction can propagate type information up
@@ -967,8 +977,4 @@ void ConjunctionStep::restoreOuterState() const {
967977 for (auto &constraint : CS.ActiveConstraints )
968978 constraint.setActive (true );
969979 }
970-
971- // Restore score to the one before conjunction. This has
972- // be done after solution, reached for the body, is applied.
973- CS.CurrentScore = CurrentScore;
974980}
0 commit comments