[ConstraintSystem] Make contextual function type available for matchCallArguments

Helps diagnostics to avoid digging this type out from locator.
This commit is contained in:
Pavel Yaskevich
2019-02-28 16:53:11 -08:00
parent 86bcecf5fc
commit e33a3402cb
5 changed files with 25 additions and 13 deletions

View File

@@ -792,21 +792,24 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
class ArgumentFailureTracker : public MatchCallArgumentListener {
ConstraintSystem &CS;
FunctionType *ContextualType;
SmallVectorImpl<AnyFunctionType::Param> &Arguments;
ArrayRef<AnyFunctionType::Param> Parameters;
SmallVectorImpl<ParamBinding> &Bindings;
ConstraintLocatorBuilder Locator;
unsigned NumSynthesizedArgs = 0;
public:
ArgumentFailureTracker(ConstraintSystem &cs,
ArgumentFailureTracker(ConstraintSystem &cs, FunctionType *contextualType,
SmallVectorImpl<AnyFunctionType::Param> &args,
ArrayRef<AnyFunctionType::Param> params,
SmallVectorImpl<ParamBinding> &bindings,
ConstraintLocatorBuilder locator)
: CS(cs), Arguments(args), Parameters(params), Bindings(bindings),
Locator(locator) {}
: CS(cs), ContextualType(contextualType), Arguments(args),
Parameters(params), Bindings(bindings), Locator(locator) {}
~ArgumentFailureTracker() override {
if (NumSynthesizedArgs > 0) {
@@ -854,7 +857,7 @@ public:
return true;
return CS.recordFix(RemoveExtraneousArguments::create(
CS, argIndices, CS.getConstraintLocator(Locator)));
CS, ContextualType, argIndices, CS.getConstraintLocator(Locator)));
}
bool missingLabel(unsigned paramIndex) override {
@@ -914,7 +917,8 @@ public:
// Match the argument of a call to the parameter.
ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
ConstraintSystem &cs, ArrayRef<AnyFunctionType::Param> args,
ConstraintSystem &cs, FunctionType *contextualType,
ArrayRef<AnyFunctionType::Param> args,
ArrayRef<AnyFunctionType::Param> params, ConstraintKind subKind,
ConstraintLocatorBuilder locator) {
// Extract the parameters.
@@ -971,7 +975,7 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
// Match up the call arguments to the parameters.
SmallVector<ParamBinding, 4> parameterBindings;
{
ArgumentFailureTracker listener(cs, argsWithLabels, params,
ArgumentFailureTracker listener(cs, contextualType, argsWithLabels, params,
parameterBindings, locator);
if (constraints::matchCallArguments(
argsWithLabels, params, paramInfo, hasTrailingClosure,
@@ -1401,6 +1405,7 @@ static bool fixMissingArguments(ConstraintSystem &cs, Expr *anchor,
}
static bool fixExtraneousArguments(ConstraintSystem &cs,
FunctionType *contextualType,
SmallVectorImpl<AnyFunctionType::Param> &args,
int numExtraneous,
ConstraintLocatorBuilder locator) {
@@ -1421,7 +1426,7 @@ static bool fixExtraneousArguments(ConstraintSystem &cs,
} while (--numExtraneous);
return cs.recordFix(RemoveExtraneousArguments::create(
cs, extraneous, cs.getConstraintLocator(locator)));
cs, contextualType, extraneous, cs.getConstraintLocator(locator)));
}
ConstraintSystem::TypeMatchResult
@@ -1651,7 +1656,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
} else {
// If there are extraneous arguments, let's remove
// them from the list.
if (fixExtraneousArguments(*this, func1Params, diff, locator))
if (fixExtraneousArguments(*this, func2, func1Params, diff, locator))
return getTypeMatchFailure(argumentLocator);
}
}
@@ -6933,7 +6938,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
// The argument type must be convertible to the input type.
if (::matchCallArguments(
*this, func1->getParams(), func2->getParams(), subKind,
*this, func2, func1->getParams(), func2->getParams(), subKind,
outerLocator.withPathElement(ConstraintLocator::ApplyArgument))
.isFailure())
return SolutionKind::Error;