Skip to content

Commit 73084e7

Browse files
committed
[CSStep] Make sure disjunction choices with value conversions are not considered "the best"
Augment `DisjunctionChoice::{shouldSkip, shouldStopAt}` to check for presence of implicit value conversions, and if score indicates that there is at least one of those was attempted - downgrade importance of a last successful choice.
1 parent 9d9a8d6 commit 73084e7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Sema/CSStep.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ bool DisjunctionStep::shouldStopAt(const DisjunctionChoice &choice) const {
710710
auto *lastChoice = LastSolvedChoice->first;
711711
auto delta = LastSolvedChoice->second - getCurrentScore();
712712
bool hasUnavailableOverloads = delta.Data[SK_Unavailable] > 0;
713+
bool hasImplicitConversions = delta.Data[SK_ImplicitValueConversion] > 0;
713714
bool hasFixes = delta.Data[SK_Fix] > 0;
714715
bool hasAsyncMismatch = delta.Data[SK_AsyncInSyncMismatch] > 0;
715716
auto isBeginningOfPartition = choice.isBeginningOfPartition();
@@ -719,7 +720,9 @@ bool DisjunctionStep::shouldStopAt(const DisjunctionChoice &choice) const {
719720
// 1. selecting unavailable overloads
720721
// 2. result in fixes being applied to reach a solution
721722
// 3. selecting an overload that results in an async/sync mismatch
723+
// 4. implicit value conversions
722724
return !hasUnavailableOverloads && !hasFixes && !hasAsyncMismatch &&
725+
!hasImplicitConversions &&
723726
(isBeginningOfPartition ||
724727
shortCircuitDisjunctionAt(choice, lastChoice));
725728
}

lib/Sema/CSStep.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,11 @@ class DisjunctionStep final : public BindingStep<DisjunctionChoiceProducer> {
691691
// non-generic score indicates that there were no forced
692692
// unwrappings of optional(s), no unavailable overload
693693
// choices present in the solution, no fixes required,
694-
// and there are no non-trivial function conversions.
694+
// and there are no non-trivial function or value conversions.
695695
auto &score = BestNonGenericScore->Data;
696696
return (score[SK_ForceUnchecked] == 0 && score[SK_Unavailable] == 0 &&
697-
score[SK_Fix] == 0 && score[SK_FunctionConversion] == 0);
697+
score[SK_Fix] == 0 && score[SK_FunctionConversion] == 0 &&
698+
score[SK_ImplicitValueConversion] == 0);
698699
}
699700

700701
/// Attempt to apply given disjunction choice to constraint system.

0 commit comments

Comments
 (0)