@@ -110,36 +110,31 @@ bool constraints::doesMemberRefApplyCurriedSelf(Type baseTy,
110
110
// curried self.
111
111
if (decl->isInstanceMember ()) {
112
112
assert (baseTy);
113
- if (isa<AbstractFunctionDecl>(decl) && baseTy->is <AnyMetatypeType>())
113
+ if (isa<AbstractFunctionDecl>(decl) &&
114
+ baseTy->getRValueType ()->is <AnyMetatypeType>())
114
115
return false ;
115
116
}
116
117
117
118
// Otherwise the reference applies self.
118
119
return true ;
119
120
}
120
121
121
- bool constraints::areConservativelyCompatibleArgumentLabels (
122
- OverloadChoice choice,
123
- ArrayRef<Identifier> labels ,
124
- bool hasTrailingClosure) {
122
+ static bool
123
+ areConservativelyCompatibleArgumentLabels ( OverloadChoice choice,
124
+ ArrayRef<FunctionType::Param> args ,
125
+ bool hasTrailingClosure) {
125
126
ValueDecl *decl = nullptr ;
126
- Type baseType;
127
127
switch (choice.getKind ()) {
128
128
case OverloadChoiceKind::Decl:
129
129
case OverloadChoiceKind::DeclViaBridge:
130
130
case OverloadChoiceKind::DeclViaDynamic:
131
131
case OverloadChoiceKind::DeclViaUnwrappedOptional:
132
132
decl = choice.getDecl ();
133
- baseType = choice.getBaseType ();
134
- if (baseType)
135
- baseType = baseType->getRValueType ();
136
133
break ;
137
134
138
- case OverloadChoiceKind::KeyPathApplication:
139
- // Key path applications are written as if subscript[keyPath:].
140
- return !hasTrailingClosure && labels.size () == 1 && labels[0 ].is (" keyPath" );
141
-
142
135
case OverloadChoiceKind::BaseType:
136
+ // KeyPath application is not filtered in `performMemberLookup`.
137
+ case OverloadChoiceKind::KeyPathApplication:
143
138
case OverloadChoiceKind::DynamicMemberLookup:
144
139
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
145
140
case OverloadChoiceKind::TupleIndex:
@@ -149,17 +144,13 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
149
144
if (!decl->hasParameterList ())
150
145
return true ;
151
146
152
- SmallVector<AnyFunctionType::Param, 8 > argInfos;
153
- for (auto argLabel : labels) {
154
- argInfos.push_back (AnyFunctionType::Param (Type (), argLabel, {}));
155
- }
156
-
157
147
// This is a member lookup, which generally means that the call arguments
158
148
// (if we have any) will apply to the second level of parameters, with
159
149
// the member lookup applying the curried self at the first level. But there
160
150
// are cases where we can get an unapplied declaration reference back.
161
151
auto hasAppliedSelf =
162
- decl->hasCurriedSelf () && doesMemberRefApplyCurriedSelf (baseType, decl);
152
+ decl->hasCurriedSelf () &&
153
+ doesMemberRefApplyCurriedSelf (choice.getBaseType (), decl);
163
154
164
155
auto *fnType = decl->getInterfaceType ()->castTo <AnyFunctionType>();
165
156
if (hasAppliedSelf) {
@@ -173,10 +164,9 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
173
164
MatchCallArgumentListener listener;
174
165
SmallVector<ParamBinding, 8 > unusedParamBindings;
175
166
176
- return !matchCallArguments (argInfos, params, paramInfo,
177
- hasTrailingClosure,
178
- /* allow fixes*/ false ,
179
- listener, unusedParamBindings);
167
+ return !matchCallArguments (args, params, paramInfo, hasTrailingClosure,
168
+ /* allow fixes*/ false , listener,
169
+ unusedParamBindings);
180
170
}
181
171
182
172
Expr *constraints::getArgumentLabelTargetExpr (Expr *fn) {
@@ -5838,7 +5828,6 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
5838
5828
Type ConstraintSystem::simplifyAppliedOverloads (
5839
5829
TypeVariableType *fnTypeVar,
5840
5830
const FunctionType *argFnType,
5841
- Optional<ArgumentLabelState> argumentLabels,
5842
5831
ConstraintLocatorBuilder locator) {
5843
5832
Type fnType (fnTypeVar);
5844
5833
@@ -5879,6 +5868,8 @@ Type ConstraintSystem::simplifyAppliedOverloads(
5879
5868
return markFailure ();
5880
5869
};
5881
5870
5871
+ auto argumentInfo = getArgumentLabels (*this , locator);
5872
+
5882
5873
// Consider each of the constraints in the disjunction.
5883
5874
retry_after_fail:
5884
5875
bool hasUnhandledConstraints = false ;
@@ -5892,12 +5883,18 @@ Type ConstraintSystem::simplifyAppliedOverloads(
5892
5883
5893
5884
// Determine whether the argument labels we have conflict with those of
5894
5885
// this overload choice.
5895
- if (argumentLabels &&
5896
- !areConservativelyCompatibleArgumentLabels (
5897
- choice, argumentLabels->Labels ,
5898
- argumentLabels->HasTrailingClosure )) {
5899
- labelMismatch = true ;
5900
- return false ;
5886
+ if (argumentInfo) {
5887
+ auto args = argFnType->getParams ();
5888
+
5889
+ SmallVector<FunctionType::Param, 8 > argsWithLabels;
5890
+ argsWithLabels.append (args.begin (), args.end ());
5891
+ FunctionType::relabelParams (argsWithLabels, argumentInfo->Labels );
5892
+
5893
+ if (!areConservativelyCompatibleArgumentLabels (
5894
+ choice, argsWithLabels, argumentInfo->HasTrailingClosure )) {
5895
+ labelMismatch = true ;
5896
+ return false ;
5897
+ }
5901
5898
}
5902
5899
5903
5900
// Determine the type that this choice will have.
@@ -5924,7 +5921,7 @@ Type ConstraintSystem::simplifyAppliedOverloads(
5924
5921
switch (filterResult) {
5925
5922
case SolutionKind::Error:
5926
5923
if (labelMismatch && shouldAttemptFixes ()) {
5927
- argumentLabels = None ;
5924
+ argumentInfo. reset () ;
5928
5925
goto retry_after_fail;
5929
5926
}
5930
5927
@@ -6040,9 +6037,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
6040
6037
// If the right-hand side is a type variable, try to simplify the overload
6041
6038
// set.
6042
6039
if (auto typeVar = desugar2->getAs <TypeVariableType>()) {
6043
- auto argumentLabels = getArgumentLabels (*this , locator);
6044
- Type newType2 =
6045
- simplifyAppliedOverloads (typeVar, func1, argumentLabels, locator);
6040
+ Type newType2 = simplifyAppliedOverloads (typeVar, func1, locator);
6046
6041
if (!newType2)
6047
6042
return SolutionKind::Error;
6048
6043
0 commit comments