Skip to content

Commit cebbd63

Browse files
committed
Address review comments, fix test.
- Rename `isValidDynamicallyCallMethod` to `isValidDynamicCallableMethod`. - Add todo hint regarding `static func callAsFunction`, if it is to be supported. - Restore `var origType2` before unwrapping optionality. - This fixes `expr/delayed-ident/static_var.swift`.
1 parent 4cb7ebf commit cebbd63

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6753,7 +6753,7 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
67536753

67546754
// Returns true if the given method and method type are a valid
67556755
// `@dynamicCallable` required `func dynamicallyCall` method.
6756-
static bool isValidDynamicallyCallMethod(FuncDecl *method,
6756+
static bool isValidDynamicCallableMethod(FuncDecl *method,
67576757
AnyFunctionType *methodType) {
67586758
auto &ctx = method->getASTContext();
67596759
if (method->getName() != ctx.Id_dynamicallyCall)
@@ -6815,7 +6815,7 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
68156815
arg = TupleExpr::createImplicit(ctx, parenExpr->getSubExpr(), {});
68166816

68176817
// Get resolved `dynamicallyCall` method and verify it.
6818-
assert(isValidDynamicallyCallMethod(method, methodType));
6818+
assert(isValidDynamicCallableMethod(method, methodType));
68196819
auto params = methodType->getParams();
68206820
auto argumentType = params[0].getParameterType();
68216821

@@ -7043,7 +7043,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
70437043
if (method->isCallAsFunctionMethod())
70447044
return finishApplyCallAsFunctionMethod(
70457045
*this, apply, *selected, methodType, applyFunctionLoc);
7046-
if (methodType && isValidDynamicallyCallMethod(method, methodType))
7046+
if (methodType && isValidDynamicCallableMethod(method, methodType))
70477047
return finishApplyDynamicCallable(
70487048
apply, *selected, method, methodType, applyFunctionLoc);
70497049
}

lib/Sema/CSSimplify.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6012,15 +6012,16 @@ ConstraintSystem::simplifyApplicableFnConstraint(
60126012
}
60136013
}
60146014

6015-
// Before stripping lvalue-ness and optional types, save original type for
6016-
// handling `func callAsFunction` and `@dynamicCallable` applications.
6017-
// This supports the following cases:
6015+
// Before stripping lvalue-ness and optional types, save the original second
6016+
// type for handling `func callAsFunction` and `@dynamicCallable`
6017+
// applications. This supports the following cases:
60186018
// - Generating constraints for `mutating func callAsFunction`. The nominal
60196019
// type (`type2`) should be an lvalue type.
60206020
// - Extending `Optional` itself with `func callAsFunction` or
60216021
// `@dynamicCallable` functionality. Optional types are stripped below if
60226022
// `shouldAttemptFixes()` is true.
6023-
auto *origType2 = type2->getDesugaredType();
6023+
auto origLValueType2 =
6024+
getFixedTypeRecursive(type2, flags, /*wantRValue=*/false);
60246025
// Drill down to the concrete type on the right hand side.
60256026
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
60266027
auto desugar2 = type2->getDesugaredType();
@@ -6104,10 +6105,10 @@ ConstraintSystem::simplifyApplicableFnConstraint(
61046105
outerLocator.withPathElement(ConstraintLocator::Member));
61056106
// Add a `callAsFunction` member constraint, binding the member type to a
61066107
// type variable.
6107-
auto memberTy = createTypeVariable(memberLoc, TVO_CanBindToLValue |
6108-
TVO_CanBindToNoEscape |
6109-
TVO_CanBindToInOut);
6110-
addValueMemberConstraint(origType2, DeclName(ctx.Id_callAsFunction),
6108+
auto memberTy = createTypeVariable(memberLoc, /*options=*/0);
6109+
// TODO: Revisit this if `static func callAsFunction` is to be supported.
6110+
// Static member constraint requires `FunctionRefKind::DoubleApply`.
6111+
addValueMemberConstraint(origLValueType2, DeclName(ctx.Id_callAsFunction),
61116112
memberTy, DC, FunctionRefKind::SingleApply,
61126113
/*outerAlternatives*/ {}, locator);
61136114
// Add new applicable function constraint based on the member type
@@ -6117,6 +6118,8 @@ ConstraintSystem::simplifyApplicableFnConstraint(
61176118
return SolutionKind::Solved;
61186119
}
61196120

6121+
// Record the second type before unwrapping optionals.
6122+
auto origType2 = desugar2;
61206123
unsigned unwrapCount = 0;
61216124
if (shouldAttemptFixes()) {
61226125
// If we have an optional type, try forcing it to see if that

0 commit comments

Comments
 (0)