mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user