[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

@@ -7391,18 +7391,16 @@ ConstraintSystem::simplifyApplicableFnConstraint(
// is true.
if (desugar2->isCallableNominalType(DC)) {
auto memberLoc = getConstraintLocator(
outerLocator.withPathElement(ConstraintLocator::Member));
locator.withPathElement(ConstraintLocator::ImplicitCallAsFunction));
// Add a `callAsFunction` member constraint, binding the member type to a
// type variable.
auto memberTy = createTypeVariable(memberLoc, /*options=*/0);
// TODO: Revisit this if `static func callAsFunction` is to be supported.
// Static member constraint requires `FunctionRefKind::DoubleApply`.
// TODO: Use a custom locator element to identify this member constraint
// instead of just pointing to the function expr.
addValueMemberConstraint(origLValueType2,
DeclNameRef(ctx.Id_callAsFunction),
memberTy, DC, FunctionRefKind::SingleApply,
/*outerAlternatives*/ {}, locator);
/*outerAlternatives*/ {}, memberLoc);
// Add new applicable function constraint based on the member type
// variable.
addConstraint(ConstraintKind::ApplicableFunction, func1, memberTy,