Use hasAppliedSelf in getFunctionArgApplyInfo

`callee->hasCurriedSelf()` isn't the correct check
here when we have an argument mismatch for the
self parameter in a curried application.
This commit is contained in:
Hamish Knight
2019-10-01 14:45:41 -07:00
parent b5a0d58dc0
commit ec45b24b63
4 changed files with 25 additions and 18 deletions

View File

@@ -221,12 +221,12 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
if (!argExpr)
return None;
ValueDecl *callee = nullptr;
Optional<OverloadChoice> choice;
Type rawFnType;
if (auto overload = getChoiceFor(argLocator)) {
// If we have resolved an overload for the callee, then use that to get the
// function type and callee.
callee = overload->choice.getDeclOrNull();
choice = overload->choice;
rawFnType = overload->openedType;
} else {
// If we didn't resolve an overload for the callee, we must be dealing with
@@ -249,6 +249,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
// Resolve the interface type for the function. Note that this may not be a
// function type, for example it could be a generic parameter.
Type fnInterfaceType;
auto *callee = choice ? choice->getDeclOrNull() : nullptr;
if (callee && callee->hasInterfaceType()) {
// If we have a callee with an interface type, we can use it. This is
// preferable to resolveInterfaceType, as this will allow us to get a
@@ -261,7 +262,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
fnInterfaceType = callee->getInterfaceType();
// Strip off the curried self parameter if necessary.
if (callee->hasCurriedSelf())
if (hasAppliedSelf(cs, *choice))
fnInterfaceType = fnInterfaceType->castTo<AnyFunctionType>()->getResult();
if (auto *fn = fnInterfaceType->getAs<AnyFunctionType>()) {