@@ -916,7 +916,10 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
916
916
// Restore all outer type variables, constraints
917
917
// and scoring information.
918
918
Snapshot.reset ();
919
- restoreOuterState ();
919
+
920
+ // Restore original scores of outer context before
921
+ // trying to produce a combined solution.
922
+ restoreOriginalScores ();
920
923
921
924
// Apply all of the information deduced from the
922
925
// conjunction (up to the point of ambiguity)
@@ -925,6 +928,13 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
925
928
ConstraintSystem::SolverScope scope (CS);
926
929
927
930
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
+
928
938
// Note that `worseThanBestSolution` isn't checked
929
939
// here because `Solutions` were pre-filtered, and
930
940
// outer score is the same for all of them.
@@ -953,9 +963,9 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
953
963
}
954
964
955
965
void ConjunctionStep::restoreOuterState () const {
956
- // Restore best score, since upcoming step is going to
966
+ // Restore best/current score, since upcoming step is going to
957
967
// work with outer scope in relation to the conjunction.
958
- CS. solverState -> BestScore = BestScore ;
968
+ restoreOriginalScores () ;
959
969
960
970
// Active all of the previously out-of-scope constraints
961
971
// because conjunction can propagate type information up
@@ -967,8 +977,4 @@ void ConjunctionStep::restoreOuterState() const {
967
977
for (auto &constraint : CS.ActiveConstraints )
968
978
constraint.setActive (true );
969
979
}
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;
974
980
}
0 commit comments