Skip to content

Commit 6382e7b

Browse files
committed
[ConstraintSystem] Favor overloads which match choice type exactly
1 parent eebf2e2 commit 6382e7b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ class ConstraintSystem {
40044004
/// \returns \c true if an error was encountered, \c false otherwise.
40054005
bool simplifyAppliedOverloadsImpl(Constraint *disjunction,
40064006
TypeVariableType *fnTypeVar,
4007-
const FunctionType *argFnType,
4007+
FunctionType *argFnType,
40084008
unsigned numOptionalUnwraps,
40094009
ConstraintLocatorBuilder locator);
40104010

@@ -4029,7 +4029,7 @@ class ConstraintSystem {
40294029
/// call.
40304030
///
40314031
/// \returns \c true if an error was encountered, \c false otherwise.
4032-
bool simplifyAppliedOverloads(Type fnType, const FunctionType *argFnType,
4032+
bool simplifyAppliedOverloads(Type fnType, FunctionType *argFnType,
40334033
ConstraintLocatorBuilder locator);
40344034

40354035
/// Retrieve the type that will be used when matching the given overload.

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9252,7 +9252,7 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
92529252

92539253
bool ConstraintSystem::simplifyAppliedOverloadsImpl(
92549254
Constraint *disjunction, TypeVariableType *fnTypeVar,
9255-
const FunctionType *argFnType, unsigned numOptionalUnwraps,
9255+
FunctionType *argFnType, unsigned numOptionalUnwraps,
92569256
ConstraintLocatorBuilder locator) {
92579257
// Don't attempt to filter overloads when solving for code completion
92589258
// because presence of code completion token means that any call
@@ -9352,6 +9352,10 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
93529352
return true;
93539353
}
93549354

9355+
// If types lined up exactly, let's favor this overload choice.
9356+
if (Type(argFnType)->isEqual(choiceType))
9357+
constraint->setFavored();
9358+
93559359
// Account for any optional unwrapping/binding
93569360
for (unsigned i : range(numOptionalUnwraps)) {
93579361
(void)i;
@@ -9439,8 +9443,7 @@ bool ConstraintSystem::simplifyAppliedOverloads(
94399443
}
94409444

94419445
bool ConstraintSystem::simplifyAppliedOverloads(
9442-
Type fnType, const FunctionType *argFnType,
9443-
ConstraintLocatorBuilder locator) {
9446+
Type fnType, FunctionType *argFnType, ConstraintLocatorBuilder locator) {
94449447
// If we've already bound the function type, bail.
94459448
auto *fnTypeVar = fnType->getAs<TypeVariableType>();
94469449
if (!fnTypeVar || getFixedType(fnTypeVar))

0 commit comments

Comments
 (0)