@@ -5469,124 +5469,6 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
5469
5469
return false ;
5470
5470
}
5471
5471
5472
- // / Attach a Fix-It to the given diagnostic to give the trailing closure
5473
- // / argument a label.
5474
- static void labelTrailingClosureArgument (
5475
- ASTContext &ctx, Expr *fn, Expr *arg, Identifier paramName,
5476
- Expr *trailingClosure, InFlightDiagnostic &diag) {
5477
- // Dig out source locations.
5478
- SourceLoc existingRParenLoc;
5479
- SourceLoc leadingCommaLoc;
5480
- if (auto tupleExpr = dyn_cast<TupleExpr>(arg)) {
5481
- existingRParenLoc = tupleExpr->getRParenLoc ();
5482
- assert (tupleExpr->getNumElements () >= 2 && " Should be a ParenExpr?" );
5483
- leadingCommaLoc = Lexer::getLocForEndOfToken (
5484
- ctx.SourceMgr ,
5485
- tupleExpr->getElements ()[tupleExpr->getNumElements ()-2 ]->getEndLoc ());
5486
- } else {
5487
- auto parenExpr = cast<ParenExpr>(arg);
5488
- existingRParenLoc = parenExpr->getRParenLoc ();
5489
- }
5490
-
5491
- // Figure out the text to be inserted before the trailing closure.
5492
- SmallString<16 > insertionText;
5493
- SourceLoc insertionLoc;
5494
- if (leadingCommaLoc.isValid ()) {
5495
- insertionText += " , " ;
5496
- assert (existingRParenLoc.isValid ());
5497
- insertionLoc = leadingCommaLoc;
5498
- } else if (existingRParenLoc.isInvalid ()) {
5499
- insertionText += " (" ;
5500
- insertionLoc = Lexer::getLocForEndOfToken (
5501
- ctx.SourceMgr , fn->getEndLoc ());
5502
- } else {
5503
- insertionLoc = existingRParenLoc;
5504
- }
5505
-
5506
- // Add the label, if there is one.
5507
- if (!paramName.empty ()) {
5508
- insertionText += paramName.str ();
5509
- insertionText += " : " ;
5510
- }
5511
-
5512
- // If there is an existing right parentheses, remove it while we
5513
- // insert the new text.
5514
- if (existingRParenLoc.isValid ()) {
5515
- SourceLoc afterExistingRParenLoc = Lexer::getLocForEndOfToken (
5516
- ctx.SourceMgr , existingRParenLoc);
5517
- diag.fixItReplaceChars (
5518
- insertionLoc, afterExistingRParenLoc, insertionText);
5519
- } else {
5520
- // Insert the appropriate prefix.
5521
- diag.fixItInsert (insertionLoc, insertionText);
5522
- }
5523
-
5524
- // Insert a right parenthesis after the closing '}' of the trailing closure;
5525
- SourceLoc newRParenLoc = Lexer::getLocForEndOfToken (
5526
- ctx.SourceMgr , trailingClosure->getEndLoc ());
5527
- diag.fixItInsert (newRParenLoc, " )" );
5528
- }
5529
-
5530
- // / Find the trailing closure argument of a tuple or parenthesized expression.
5531
- // /
5532
- // / Due to a quirk of the backward scan that could allow reordering of
5533
- // / arguments in the presence of a trailing closure, it might not be the last
5534
- // / argument in the tuple.
5535
- static Expr *findTrailingClosureArgument (Expr *arg) {
5536
- if (auto parenExpr = dyn_cast<ParenExpr>(arg)) {
5537
- return parenExpr->getSubExpr ();
5538
- }
5539
-
5540
- auto tupleExpr = cast<TupleExpr>(arg);
5541
- SourceLoc endLoc = tupleExpr->getEndLoc ();
5542
- for (Expr *elt : llvm::reverse (tupleExpr->getElements ())) {
5543
- if (elt->getEndLoc () == endLoc)
5544
- return elt;
5545
- }
5546
-
5547
- return tupleExpr->getElements ().back ();
5548
- }
5549
-
5550
- // / Find the index of the parameter that binds the given argument.
5551
- static unsigned findParamBindingArgument (
5552
- ArrayRef<ParamBinding> parameterBindings, unsigned argIndex) {
5553
- for (unsigned paramIdx : indices (parameterBindings)) {
5554
- if (llvm::find (parameterBindings[paramIdx], argIndex)
5555
- != parameterBindings[paramIdx].end ())
5556
- return paramIdx;
5557
- }
5558
-
5559
- llvm_unreachable (" No parameter binds the argument?" );
5560
- }
5561
-
5562
- // / Warn about the use of the deprecated "backward" scan for matching the
5563
- // / unlabeled trailing closure. It was needed to properly type check, but
5564
- // / this code will break with a future version of Swift.
5565
- static void warnAboutTrailingClosureBackwardScan (
5566
- ConcreteDeclRef callee, Expr *fn, Expr *arg,
5567
- ArrayRef<AnyFunctionType::Param> params,
5568
- Optional<unsigned > unlabeledTrailingClosureIndex,
5569
- ArrayRef<ParamBinding> parameterBindings) {
5570
-
5571
- Expr *trailingClosure = findTrailingClosureArgument (arg);
5572
- unsigned paramIdx = findParamBindingArgument (
5573
- parameterBindings, *unlabeledTrailingClosureIndex);
5574
- ASTContext &ctx = params[paramIdx].getPlainType ()->getASTContext ();
5575
- Identifier paramName = params[paramIdx].getLabel ();
5576
-
5577
- {
5578
- auto diag = ctx.Diags .diagnose (
5579
- trailingClosure->getStartLoc (),
5580
- diag::unlabeled_trailing_closure_deprecated, paramName);
5581
- labelTrailingClosureArgument (
5582
- ctx, fn, arg, paramName, trailingClosure, diag);
5583
- }
5584
-
5585
- if (auto decl = callee.getDecl ()) {
5586
- ctx.Diags .diagnose (decl, diag::decl_declared_here, decl->getName ());
5587
- }
5588
- }
5589
-
5590
5472
Expr *ExprRewriter::coerceCallArguments (
5591
5473
Expr *arg, AnyFunctionType *funcType,
5592
5474
ConcreteDeclRef callee,
@@ -5678,13 +5560,6 @@ Expr *ExprRewriter::coerceCallArguments(
5678
5560
// FIXME: Eventually, we want to enforce that we have either argTuple or
5679
5561
// argParen here.
5680
5562
5681
- // Warn about the backward scan being deprecated.
5682
- if (trailingClosureMatching == TrailingClosureMatching::Backward) {
5683
- warnAboutTrailingClosureBackwardScan (
5684
- callee, apply ? apply->getFn () : nullptr , arg, params,
5685
- unlabeledTrailingClosureIndex, parameterBindings);
5686
- }
5687
-
5688
5563
SourceLoc lParenLoc, rParenLoc;
5689
5564
if (argTuple) {
5690
5565
lParenLoc = argTuple->getLParenLoc ();
0 commit comments