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