[CS] Use custom locator element for callAsFunction

Introduce a `ImplicitCallAsFunction` locator path
element to represent an implicit member reference
to `callAsFunction`. Then adjust CSApply a little
to check whether it's finishing an apply for a
callable type, and if so build the implicit member
access.
This commit is contained in:
Hamish Knight
2019-12-06 09:44:18 -08:00
parent ee5ce77c7f
commit 40d11716f7
5 changed files with 33 additions and 23 deletions

View File

@@ -506,9 +506,11 @@ ConstraintSystem::getCalleeLocator(ConstraintLocator *locator,
}
// Handle an apply of a nominal type which supports callAsFunction.
if (fnTy->isCallableNominalType(DC))
return getConstraintLocator(anchor, ConstraintLocator::ApplyFunction);
if (fnTy->isCallableNominalType(DC)) {
return getConstraintLocator(anchor,
{LocatorPathElt::ApplyFunction(),
LocatorPathElt::ImplicitCallAsFunction()});
}
return nullptr;
};
@@ -3145,8 +3147,9 @@ void constraints::simplifyLocator(Expr *&anchor,
case ConstraintLocator::LValueConversion:
case ConstraintLocator::RValueAdjustment:
case ConstraintLocator::UnresolvedMember:
// Arguments in autoclosure positions, lvalue and rvalue adjustments, and
// scalar-to-tuple conversions, and unresolved members are
case ConstraintLocator::ImplicitCallAsFunction:
// Arguments in autoclosure positions, lvalue and rvalue adjustments,
// unresolved members, and implicit callAsFunction references are
// implicit.
path = path.slice(1);
continue;