@@ -1180,13 +1180,16 @@ namespace {
11801180 // / the call. Otherwise, a specific level describing which parameter level
11811181 // / we're applying.
11821182 // / \param argLabels The argument labels provided for the call.
1183+ // / \param hasTrailingClosure Whether the last argument is a trailing
1184+ // / closure.
11831185 // / \param locator Locator used to describe where in this expression we are.
11841186 // /
11851187 // / \returns the coerced expression, which will have type \c ToType.
11861188 Expr *
11871189 coerceCallArguments (Expr *arg, Type paramType,
11881190 llvm::PointerUnion<ApplyExpr *, LevelTy> applyOrLevel,
11891191 ArrayRef<Identifier> argLabels,
1192+ bool hasTrailingClosure,
11901193 ConstraintLocatorBuilder locator);
11911194
11921195 // / \brief Coerce the given object argument (e.g., for the base of a
@@ -1215,6 +1218,7 @@ namespace {
12151218 // / \param isImplicit Whether this is an implicit subscript.
12161219 Expr *buildSubscript (Expr *base, Expr *index,
12171220 ArrayRef<Identifier> argLabels,
1221+ bool hasTrailingClosure,
12181222 ConstraintLocatorBuilder locator,
12191223 bool isImplicit, AccessSemantics semantics) {
12201224 // Determine the declaration selected for this subscript operation.
@@ -1259,6 +1263,7 @@ namespace {
12591263 // Coerce the index argument.
12601264 index = coerceCallArguments (
12611265 index, indexTy, LevelTy (1 ), argLabels,
1266+ hasTrailingClosure,
12621267 locator.withPathElement (ConstraintLocator::SubscriptIndex));
12631268 if (!index)
12641269 return nullptr ;
@@ -1274,11 +1279,10 @@ namespace {
12741279 return nullptr ;
12751280
12761281 // TODO: diagnose if semantics != AccessSemantics::Ordinary?
1277- auto subscriptExpr = new (tc.Context ) DynamicSubscriptExpr ( base,
1278- index,
1279- subscript );
1282+ auto subscriptExpr = DynamicSubscriptExpr::create (tc.Context , base,
1283+ index, subscript ,
1284+ isImplicit );
12801285 subscriptExpr->setType (resultTy);
1281- subscriptExpr->setImplicit (isImplicit);
12821286 Expr *result = subscriptExpr;
12831287 closeExistential (result);
12841288 return result;
@@ -1310,12 +1314,11 @@ namespace {
13101314
13111315 // Form the generic subscript expression.
13121316 auto subscriptExpr
1313- = new (tc.Context ) SubscriptExpr (base, index,
1314- ConcreteDeclRef (tc.Context ,
1315- subscript,
1316- substitutions),
1317- isImplicit,
1318- semantics);
1317+ = SubscriptExpr::create (tc.Context , base, index,
1318+ ConcreteDeclRef (tc.Context , subscript,
1319+ substitutions),
1320+ isImplicit,
1321+ semantics);
13191322 subscriptExpr->setType (resultTy);
13201323 subscriptExpr->setIsSuper (isSuper);
13211324
@@ -1337,8 +1340,8 @@ namespace {
13371340
13381341 // Form a normal subscript.
13391342 auto *subscriptExpr
1340- = new (tc.Context ) SubscriptExpr ( base, index, subscript,
1341- isImplicit, semantics);
1343+ = SubscriptExpr::create (tc.Context , base, index, subscript,
1344+ isImplicit, semantics);
13421345 subscriptExpr->setType (resultTy);
13431346 subscriptExpr->setIsSuper (isSuper);
13441347 Expr *result = subscriptExpr;
@@ -2603,9 +2606,9 @@ namespace {
26032606 }
26042607
26052608 Expr *visitSubscriptExpr (SubscriptExpr *expr) {
2606- SmallVector<Identifier, 2 > argLabelsScratch;
26072609 return buildSubscript (expr->getBase (), expr->getIndex (),
2608- expr->getArgumentLabels (argLabelsScratch),
2610+ expr->getArgumentLabels (),
2611+ expr->hasTrailingClosure (),
26092612 cs.getConstraintLocator (expr),
26102613 expr->isImplicit (),
26112614 expr->getAccessSemantics ());
@@ -2747,9 +2750,9 @@ namespace {
27472750 }
27482751
27492752 Expr *visitDynamicSubscriptExpr (DynamicSubscriptExpr *expr) {
2750- SmallVector<Identifier, 2 > argLabelsScratch;
27512753 return buildSubscript (expr->getBase (), expr->getIndex (),
2752- expr->getArgumentLabels (argLabelsScratch),
2754+ expr->getArgumentLabels (),
2755+ expr->hasTrailingClosure (),
27532756 cs.getConstraintLocator (expr),
27542757 expr->isImplicit (), AccessSemantics::Ordinary);
27552758 }
@@ -4638,6 +4641,7 @@ Expr *ExprRewriter::coerceCallArguments(
46384641 Expr *arg, Type paramType,
46394642 llvm::PointerUnion<ApplyExpr *, LevelTy> applyOrLevel,
46404643 ArrayRef<Identifier> argLabels,
4644+ bool hasTrailingClosure,
46414645 ConstraintLocatorBuilder locator) {
46424646
46434647 bool allParamsMatch = arg->getType ()->isEqual (paramType);
@@ -4704,7 +4708,7 @@ Expr *ExprRewriter::coerceCallArguments(
47044708
47054709 SmallVector<ParamBinding, 4 > parameterBindings;
47064710 bool failed = constraints::matchCallArguments (args, params,
4707- hasTrailingClosure (locator) ,
4711+ hasTrailingClosure,
47084712 /* allowFixes=*/ false , listener,
47094713 parameterBindings);
47104714 assert (!failed && " Call arguments did not match up?" );
@@ -5922,9 +5926,12 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
59225926 SmallVector<Identifier, 2 > argLabelsScratch;
59235927 if (auto fnType = fn->getType ()->getAs <FunctionType>()) {
59245928 auto origArg = apply->getArg ();
5929+ bool hasTrailingClosure =
5930+ isa<CallExpr>(apply) && cast<CallExpr>(apply)->hasTrailingClosure ();
59255931 Expr *arg = coerceCallArguments (origArg, fnType->getInput (),
59265932 apply,
59275933 apply->getArgumentLabels (argLabelsScratch),
5934+ hasTrailingClosure,
59285935 locator.withPathElement (
59295936 ConstraintLocator::ApplyArgument));
59305937 if (!arg) {
0 commit comments