Skip to content

Commit 1903681

Browse files
[SR-12239] Adjusting ambiguit check to use solution argument binding to map arg to param
1 parent 2e4ea3b commit 1903681

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,24 +3761,31 @@ static bool diagnoseContextualFunctionCallGenericAmbiguity(
37613761
if (!GP)
37623762
return false;
37633763

3764-
auto typeParamResultInvolvesTypeVar =
3765-
[&cs, &applyFnType](unsigned paramIdx, TypeVariableType *typeVar) {
3766-
assert(paramIdx < applyFnType->getNumParams());
3767-
auto param = applyFnType->getParams()[paramIdx];
3768-
if (param.isVariadic()) {
3769-
auto paramType = param.getParameterType();
3770-
// Variadic parameter is constructed as an ArraySliceType(which is
3771-
// just sugared type for a bound generic) with the closure type as
3772-
// element.
3773-
auto baseType =
3774-
paramType->getDesugaredType()->castTo<BoundGenericType>();
3775-
auto paramFnType =
3776-
baseType->getGenericArgs()[0]->castTo<FunctionType>();
3777-
return cs.typeVarOccursInType(typeVar, paramFnType->getResult());
3778-
}
3779-
auto paramFnType = param.getParameterType()->castTo<FunctionType>();
3780-
return cs.typeVarOccursInType(typeVar, paramFnType->getResult());
3781-
};
3764+
auto applyLoc =
3765+
cs.getConstraintLocator(AE, {LocatorPathElt::ApplyArgument()});
3766+
auto argMatching =
3767+
contextualFix.first->argumentMatchingChoices.find(applyLoc);
3768+
if (argMatching == contextualFix.first->argumentMatchingChoices.end()) {
3769+
return false;
3770+
}
3771+
3772+
auto typeParamResultInvolvesTypeVar = [&cs, &applyFnType, &argMatching](
3773+
unsigned argIdx,
3774+
TypeVariableType *typeVar) {
3775+
auto argParamMatch = argMatching->second.parameterBindings[argIdx];
3776+
auto param = applyFnType->getParams()[argParamMatch.front()];
3777+
if (param.isVariadic()) {
3778+
auto paramType = param.getParameterType();
3779+
// Variadic parameter is constructed as an ArraySliceType(which is
3780+
// just sugared type for a bound generic) with the closure type as
3781+
// element.
3782+
auto baseType = paramType->getDesugaredType()->castTo<BoundGenericType>();
3783+
auto paramFnType = baseType->getGenericArgs()[0]->castTo<FunctionType>();
3784+
return cs.typeVarOccursInType(typeVar, paramFnType->getResult());
3785+
}
3786+
auto paramFnType = param.getParameterType()->castTo<FunctionType>();
3787+
return cs.typeVarOccursInType(typeVar, paramFnType->getResult());
3788+
};
37823789

37833790
llvm::SmallVector<ClosureExpr *, 4> closureArguments;
37843791
// A single closure argument.

0 commit comments

Comments
 (0)