@@ -135,7 +135,8 @@ bool constraints::doesMemberRefApplyCurriedSelf(Type baseTy,
135135}
136136
137137static bool areConservativelyCompatibleArgumentLabels(
138- OverloadChoice choice, SmallVectorImpl<FunctionType::Param> &args,
138+ ConstraintSystem &cs, OverloadChoice choice,
139+ SmallVectorImpl<FunctionType::Param> &args,
139140 MatchCallArgumentListener &listener,
140141 Optional<unsigned> unlabeledTrailingClosureArgIndex) {
141142 ValueDecl *decl = nullptr;
@@ -155,23 +156,35 @@ static bool areConservativelyCompatibleArgumentLabels(
155156 return true;
156157 }
157158
158- if (!decl->hasParameterList())
159- return true;
160-
161- // This is a member lookup, which generally means that the call arguments
162- // (if we have any) will apply to the second level of parameters, with
163- // the member lookup applying the curried self at the first level. But there
164- // are cases where we can get an unapplied declaration reference back.
159+ // If this is a member lookup, the call arguments (if we have any) will
160+ // generally be applied to the second level of parameters, with the member
161+ // lookup applying the curried self at the first level. But there are cases
162+ // where we can get an unapplied declaration reference back.
165163 auto hasAppliedSelf =
166164 decl->hasCurriedSelf() &&
167165 doesMemberRefApplyCurriedSelf(choice.getBaseType(), decl);
168166
169- auto *fnType = decl->getInterfaceType()->castTo<AnyFunctionType>();
170- if (hasAppliedSelf) {
171- fnType = fnType->getResult()->getAs<AnyFunctionType>();
172- assert(fnType && "Parameter list curry level does not match type");
167+ AnyFunctionType *fnType = nullptr;
168+ if (decl->hasParameterList()) {
169+ fnType = decl->getInterfaceType()->castTo<AnyFunctionType>();
170+ if (hasAppliedSelf) {
171+ fnType = fnType->getResult()->getAs<AnyFunctionType>();
172+ assert(fnType && "Parameter list curry level does not match type");
173+ }
174+ } else if (auto *VD = dyn_cast<VarDecl>(decl)) {
175+ // For variables, we can reject any type that we know cannot be callable.
176+ auto varTy = VD->getValueInterfaceType()->lookThroughAllOptionalTypes();
177+ if (!varTy->mayBeCallable(cs.DC))
178+ return false;
179+ fnType = varTy->getAs<AnyFunctionType>();
173180 }
174181
182+ // Given we want to be conservative with this checking, if there's any case
183+ // we can't match arguments for (e.g callable nominals, type parameters),
184+ // default to returning true.
185+ if (!fnType)
186+ return true;
187+
175188 auto params = fnType->getParams();
176189 ParameterListInfo paramInfo(params, decl, hasAppliedSelf);
177190
@@ -11014,7 +11027,7 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1101411027
1101511028 auto labelsMatch = [&](MatchCallArgumentListener &listener) {
1101611029 if (areConservativelyCompatibleArgumentLabels(
11017- choice, argsWithLabels, listener,
11030+ *this, choice, argsWithLabels, listener,
1101811031 argList->getFirstTrailingClosureIndex()))
1101911032 return true;
1102011033
0 commit comments