@@ -5455,22 +5455,6 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
5455
5455
return false ;
5456
5456
}
5457
5457
5458
- // / Determine the arity of the given parameter of function type.
5459
- static unsigned functionParameterArity (AnyFunctionType::Param param) {
5460
- Type paramType = param.getPlainType ();
5461
- if (param.isVariadic ())
5462
- paramType = ParamDecl::getVarargBaseTy (paramType);
5463
-
5464
- paramType = paramType->lookThroughAllOptionalTypes ();
5465
-
5466
- if (param.isAutoClosure ()) {
5467
- paramType = paramType->castTo <AnyFunctionType>()->getResult ();
5468
- paramType = paramType->lookThroughAllOptionalTypes ();
5469
- }
5470
-
5471
- return paramType->castTo <AnyFunctionType>()->getNumParams ();
5472
- }
5473
-
5474
5458
// / Attach a Fix-It to the given diagnostic to give the trailing closure
5475
5459
// / argument a label.
5476
5460
static void labelTrailingClosureArgument (
@@ -5561,113 +5545,6 @@ static unsigned findParamBindingArgument(
5561
5545
llvm_unreachable (" No parameter binds the argument?" );
5562
5546
}
5563
5547
5564
- // / SE-0286 changed the direction in which the unlabeled trailing closure
5565
- // / argument is matched to a parameter, from backward (the pre-Swift 5.3
5566
- // / semantics) to forward (after SE-0286). Identify cases where this may
5567
- // / have resulted in a silent change in behavior.
5568
- static void maybeWarnAboutTrailingClosureBindingChange (
5569
- ConcreteDeclRef callee,
5570
- Expr *fn,
5571
- Expr *arg,
5572
- ArrayRef<AnyFunctionType::Param> args,
5573
- ArrayRef<AnyFunctionType::Param> params,
5574
- const ParameterListInfo ¶mInfo,
5575
- Optional<unsigned > unlabeledTrailingClosureIndex,
5576
- ArrayRef<ParamBinding> parameterBindings) {
5577
-
5578
- if (!unlabeledTrailingClosureIndex)
5579
- return ;
5580
-
5581
- if (*unlabeledTrailingClosureIndex != args.size () - 1 )
5582
- return ;
5583
-
5584
- // Find the parameter that bound the unlabeled trailing closure argument.
5585
- unsigned paramIdx = findParamBindingArgument (
5586
- parameterBindings, *unlabeledTrailingClosureIndex);
5587
-
5588
- // If this parameter requires an argument, it would have been unfilled
5589
- // prior to SE-2086; there is nothing to diagnose.
5590
- if (parameterRequiresArgument (params, paramInfo, paramIdx))
5591
- return ;
5592
-
5593
- // Look for a later parameter that could match a trailing closure; the
5594
- // last one of these would have been picked prior to SE-0286.
5595
- Optional<unsigned > matchingBackwardParamIdx;
5596
- for (unsigned backwardParamIdx :
5597
- range (paramIdx + 1 , parameterBindings.size ())) {
5598
- if (!paramInfo.acceptsUnlabeledTrailingClosureArgument (backwardParamIdx))
5599
- continue ;
5600
-
5601
- matchingBackwardParamIdx = backwardParamIdx;
5602
- }
5603
-
5604
- // If there is no other parameter that could match the unlabeled trailing
5605
- // closure, there is nothing to diagnose.
5606
- if (!matchingBackwardParamIdx)
5607
- return ;
5608
-
5609
- // Do a simple arity check; if the matched parameter and backward-matched
5610
- // parameter accept functions with different arity, this would not have
5611
- // type-checked with the backward scan, so there is nothing to report.
5612
- if (functionParameterArity (params[paramIdx]) !=
5613
- functionParameterArity (params[*matchingBackwardParamIdx]))
5614
- return ;
5615
-
5616
- // Dig out the trailing closure.
5617
- Expr *trailingClosure = findTrailingClosureArgument (arg);
5618
-
5619
- // Determine the names of the parameters that would be matched by the
5620
- // forward and backward scans.
5621
- Identifier paramName = params[paramIdx].getLabel ();
5622
- Identifier backwardParamName = params[*matchingBackwardParamIdx].getLabel ();
5623
-
5624
- // Produce a diagnostic referencing the callee.
5625
- ASTContext &ctx = params[paramIdx].getPlainType ()->getASTContext ();
5626
- auto noteCallee = [&] {
5627
- auto decl = callee.getDecl ();
5628
- if (!decl)
5629
- return ;
5630
-
5631
- auto diag = ctx.Diags .diagnose (
5632
- decl, diag::decl_multiple_defaulted_closure_parameters,
5633
- decl->getName (), paramName, backwardParamName);
5634
-
5635
- // Dig out the parameter declarations so we can highlight them.
5636
- if (const ParameterList *paramList = getParameterList (decl)) {
5637
- diag.highlight (paramList->get (paramIdx)->getLoc ());
5638
- diag.highlight (paramList->get (*matchingBackwardParamIdx)->getLoc ());
5639
- }
5640
- };
5641
-
5642
- // If the parameters have the same name, provide a custom diagnostic and then
5643
- // bail out early; there are no useful notes we can provide here.
5644
- if (paramName == backwardParamName) {
5645
- ctx.Diags .diagnose (trailingClosure->getStartLoc (), diag::unlabeled_trailing_closure_changed_behavior_same_param_name,
5646
- paramName);
5647
- noteCallee ();
5648
- return ;
5649
- }
5650
-
5651
- // Produce the diagnostic.
5652
- ctx.Diags .diagnose (trailingClosure->getStartLoc (), diag::unlabeled_trailing_closure_changed_behavior, paramName,
5653
- backwardParamName);
5654
-
5655
- // Produce a note with a Fix-It describing how to resolve the ambiguity.
5656
- auto diagResolution = [&](Identifier paramName, unsigned which) {
5657
- // Emit the note.
5658
- auto diag = ctx.Diags .diagnose (
5659
- trailingClosure->getStartLoc (), diag::trailing_closure_select_parameter,
5660
- paramName, which);
5661
- labelTrailingClosureArgument (
5662
- ctx, fn, arg, paramName, trailingClosure, diag);
5663
- };
5664
-
5665
- diagResolution (backwardParamName, 0 );
5666
- diagResolution (paramName, 1 );
5667
-
5668
- noteCallee ();
5669
- }
5670
-
5671
5548
// / Warn about the use of the deprecated "backward" scan for matching the
5672
5549
// / unlabeled trailing closure. It was needed to properly type check, but
5673
5550
// / this code will break with a future version of Swift.
@@ -5787,13 +5664,8 @@ Expr *ExprRewriter::coerceCallArguments(
5787
5664
// FIXME: Eventually, we want to enforce that we have either argTuple or
5788
5665
// argParen here.
5789
5666
5790
- // Warn if there was a recent change in trailing closure binding semantics
5791
- // that might have lead to a silent change in behavior.
5792
- if (trailingClosureMatching == TrailingClosureMatching::Forward) {
5793
- maybeWarnAboutTrailingClosureBindingChange (
5794
- callee, apply ? apply->getFn () : nullptr , arg, args, params, paramInfo,
5795
- unlabeledTrailingClosureIndex, parameterBindings);
5796
- } else {
5667
+ // Warn about the backward scan being deprecated.
5668
+ if (trailingClosureMatching == TrailingClosureMatching::Backward) {
5797
5669
warnAboutTrailingClosureBackwardScan (
5798
5670
callee, apply ? apply->getFn () : nullptr , arg, params,
5799
5671
unlabeledTrailingClosureIndex, parameterBindings);
0 commit comments