@@ -714,6 +714,21 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
714
714
return listener.relabelArguments (actualArgNames);
715
715
}
716
716
717
+ static bool hasAppliedSelf (ConstraintSystem &cs, const OverloadChoice &choice) {
718
+ auto *decl = choice.getDeclOrNull ();
719
+ if (!decl)
720
+ return false ;
721
+
722
+ auto baseType = choice.getBaseType ();
723
+ if (baseType)
724
+ baseType = cs.getFixedTypeRecursive (baseType, /* wantRValue=*/ true );
725
+
726
+ // In most cases where we reference a declaration with a curried self
727
+ // parameter, it gets dropped from the type of the reference.
728
+ return decl->hasCurriedSelf () &&
729
+ doesMemberRefApplyCurriedSelf (baseType, decl);
730
+ }
731
+
717
732
// / Find the callee declaration and uncurry level for a given call
718
733
// / locator.
719
734
static std::tuple<ValueDecl *, bool , ArrayRef<Identifier>, bool ,
@@ -828,16 +843,8 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
828
843
829
844
// If there's a declaration, return it.
830
845
if (auto *decl = choice->getDeclOrNull ()) {
831
- auto baseType = choice->getBaseType ();
832
- if (baseType)
833
- baseType = cs.getFixedTypeRecursive (baseType, /* wantRValue=*/ true );
834
-
835
- // In most cases where we reference a declaration with a curried self
836
- // parameter, it gets dropped from the type of the reference.
837
- bool hasAppliedSelf =
838
- decl->hasCurriedSelf () && doesMemberRefApplyCurriedSelf (baseType, decl);
839
- return std::make_tuple (decl, hasAppliedSelf, argLabels, hasTrailingClosure,
840
- calleeLocator);
846
+ return std::make_tuple (decl, hasAppliedSelf (cs, *choice), argLabels,
847
+ hasTrailingClosure, calleeLocator);
841
848
}
842
849
843
850
return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
@@ -2197,9 +2204,34 @@ bool ConstraintSystem::repairFailures(
2197
2204
// of the function value e.g. `foo = bar` or `foo = .bar`
2198
2205
auto repairByInsertingExplicitCall = [&](Type srcType, Type dstType) -> bool {
2199
2206
auto fnType = srcType->getAs <FunctionType>();
2200
- if (!fnType || fnType-> getNumParams () > 0 )
2207
+ if (!fnType)
2201
2208
return false ;
2202
2209
2210
+ // If argument is a function type and all of its parameters have
2211
+ // default values, let's see whether error is related to missing
2212
+ // explicit call.
2213
+ if (fnType->getNumParams () > 0 ) {
2214
+ auto *anchor =
2215
+ simplifyLocatorToAnchor (*this , getConstraintLocator (locator));
2216
+
2217
+ if (!anchor)
2218
+ return false ;
2219
+
2220
+ auto *overload = findSelectedOverloadFor (anchor);
2221
+ if (!(overload && overload->Choice .isDecl ()))
2222
+ return false ;
2223
+
2224
+ const auto &choice = overload->Choice ;
2225
+ ParameterListInfo info (fnType->getParams (), choice.getDecl (),
2226
+ hasAppliedSelf (*this , choice));
2227
+
2228
+ if (llvm::any_of (indices (fnType->getParams ()),
2229
+ [&info](const unsigned idx) {
2230
+ return !info.hasDefaultArgument (idx);
2231
+ }))
2232
+ return false ;
2233
+ }
2234
+
2203
2235
auto resultType = fnType->getResult ();
2204
2236
// If this is situation like `x = { ... }` where closure results in
2205
2237
// `Void`, let's not suggest to call the closure, because it's most
0 commit comments