@@ -714,6 +714,21 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
714714 return listener.relabelArguments (actualArgNames);
715715}
716716
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+
717732// / Find the callee declaration and uncurry level for a given call
718733// / locator.
719734static std::tuple<ValueDecl *, bool , ArrayRef<Identifier>, bool ,
@@ -828,16 +843,8 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
828843
829844 // If there's a declaration, return it.
830845 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);
841848 }
842849
843850 return std::make_tuple (nullptr , /* hasAppliedSelf=*/ false , argLabels,
@@ -2197,9 +2204,34 @@ bool ConstraintSystem::repairFailures(
21972204 // of the function value e.g. `foo = bar` or `foo = .bar`
21982205 auto repairByInsertingExplicitCall = [&](Type srcType, Type dstType) -> bool {
21992206 auto fnType = srcType->getAs <FunctionType>();
2200- if (!fnType || fnType-> getNumParams () > 0 )
2207+ if (!fnType)
22012208 return false ;
22022209
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+
22032235 auto resultType = fnType->getResult ();
22042236 // If this is situation like `x = { ... }` where closure results in
22052237 // `Void`, let's not suggest to call the closure, because it's most
0 commit comments