@@ -5521,22 +5521,6 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
5521
5521
return false ;
5522
5522
}
5523
5523
5524
- // / Determine the arity of the given parameter of function type.
5525
- static unsigned functionParameterArity (AnyFunctionType::Param param) {
5526
- Type paramType = param.getPlainType ();
5527
- if (param.isVariadic ())
5528
- paramType = ParamDecl::getVarargBaseTy (paramType);
5529
-
5530
- paramType = paramType->lookThroughAllOptionalTypes ();
5531
-
5532
- if (param.isAutoClosure ()) {
5533
- paramType = paramType->castTo <AnyFunctionType>()->getResult ();
5534
- paramType = paramType->lookThroughAllOptionalTypes ();
5535
- }
5536
-
5537
- return paramType->castTo <AnyFunctionType>()->getNumParams ();
5538
- }
5539
-
5540
5524
// / Attach a Fix-It to the given diagnostic to give the trailing closure
5541
5525
// / argument a label.
5542
5526
static void labelTrailingClosureArgument (
@@ -5627,113 +5611,6 @@ static unsigned findParamBindingArgument(
5627
5611
llvm_unreachable (" No parameter binds the argument?" );
5628
5612
}
5629
5613
5630
- // / SE-0286 changed the direction in which the unlabeled trailing closure
5631
- // / argument is matched to a parameter, from backward (the pre-Swift 5.3
5632
- // / semantics) to forward (after SE-0286). Identify cases where this may
5633
- // / have resulted in a silent change in behavior.
5634
- static void maybeWarnAboutTrailingClosureBindingChange (
5635
- ConcreteDeclRef callee,
5636
- Expr *fn,
5637
- Expr *arg,
5638
- ArrayRef<AnyFunctionType::Param> args,
5639
- ArrayRef<AnyFunctionType::Param> params,
5640
- const ParameterListInfo ¶mInfo,
5641
- Optional<unsigned > unlabeledTrailingClosureIndex,
5642
- ArrayRef<ParamBinding> parameterBindings) {
5643
-
5644
- if (!unlabeledTrailingClosureIndex)
5645
- return ;
5646
-
5647
- if (*unlabeledTrailingClosureIndex != args.size () - 1 )
5648
- return ;
5649
-
5650
- // Find the parameter that bound the unlabeled trailing closure argument.
5651
- unsigned paramIdx = findParamBindingArgument (
5652
- parameterBindings, *unlabeledTrailingClosureIndex);
5653
-
5654
- // If this parameter requires an argument, it would have been unfilled
5655
- // prior to SE-2086; there is nothing to diagnose.
5656
- if (parameterRequiresArgument (params, paramInfo, paramIdx))
5657
- return ;
5658
-
5659
- // Look for a later parameter that could match a trailing closure; the
5660
- // last one of these would have been picked prior to SE-0286.
5661
- Optional<unsigned > matchingBackwardParamIdx;
5662
- for (unsigned backwardParamIdx :
5663
- range (paramIdx + 1 , parameterBindings.size ())) {
5664
- if (!paramInfo.acceptsUnlabeledTrailingClosureArgument (backwardParamIdx))
5665
- continue ;
5666
-
5667
- matchingBackwardParamIdx = backwardParamIdx;
5668
- }
5669
-
5670
- // If there is no other parameter that could match the unlabeled trailing
5671
- // closure, there is nothing to diagnose.
5672
- if (!matchingBackwardParamIdx)
5673
- return ;
5674
-
5675
- // Do a simple arity check; if the matched parameter and backward-matched
5676
- // parameter accept functions with different arity, this would not have
5677
- // type-checked with the backward scan, so there is nothing to report.
5678
- if (functionParameterArity (params[paramIdx]) !=
5679
- functionParameterArity (params[*matchingBackwardParamIdx]))
5680
- return ;
5681
-
5682
- // Dig out the trailing closure.
5683
- Expr *trailingClosure = findTrailingClosureArgument (arg);
5684
-
5685
- // Determine the names of the parameters that would be matched by the
5686
- // forward and backward scans.
5687
- Identifier paramName = params[paramIdx].getLabel ();
5688
- Identifier backwardParamName = params[*matchingBackwardParamIdx].getLabel ();
5689
-
5690
- // Produce a diagnostic referencing the callee.
5691
- ASTContext &ctx = params[paramIdx].getPlainType ()->getASTContext ();
5692
- auto noteCallee = [&] {
5693
- auto decl = callee.getDecl ();
5694
- if (!decl)
5695
- return ;
5696
-
5697
- auto diag = ctx.Diags .diagnose (
5698
- decl, diag::decl_multiple_defaulted_closure_parameters,
5699
- decl->getName (), paramName, backwardParamName);
5700
-
5701
- // Dig out the parameter declarations so we can highlight them.
5702
- if (const ParameterList *paramList = getParameterList (decl)) {
5703
- diag.highlight (paramList->get (paramIdx)->getLoc ());
5704
- diag.highlight (paramList->get (*matchingBackwardParamIdx)->getLoc ());
5705
- }
5706
- };
5707
-
5708
- // If the parameters have the same name, provide a custom diagnostic and then
5709
- // bail out early; there are no useful notes we can provide here.
5710
- if (paramName == backwardParamName) {
5711
- ctx.Diags .diagnose (trailingClosure->getStartLoc (), diag::unlabeled_trailing_closure_changed_behavior_same_param_name,
5712
- paramName);
5713
- noteCallee ();
5714
- return ;
5715
- }
5716
-
5717
- // Produce the diagnostic.
5718
- ctx.Diags .diagnose (trailingClosure->getStartLoc (), diag::unlabeled_trailing_closure_changed_behavior, paramName,
5719
- backwardParamName);
5720
-
5721
- // Produce a note with a Fix-It describing how to resolve the ambiguity.
5722
- auto diagResolution = [&](Identifier paramName, unsigned which) {
5723
- // Emit the note.
5724
- auto diag = ctx.Diags .diagnose (
5725
- trailingClosure->getStartLoc (), diag::trailing_closure_select_parameter,
5726
- paramName, which);
5727
- labelTrailingClosureArgument (
5728
- ctx, fn, arg, paramName, trailingClosure, diag);
5729
- };
5730
-
5731
- diagResolution (backwardParamName, 0 );
5732
- diagResolution (paramName, 1 );
5733
-
5734
- noteCallee ();
5735
- }
5736
-
5737
5614
// / Warn about the use of the deprecated "backward" scan for matching the
5738
5615
// / unlabeled trailing closure. It was needed to properly type check, but
5739
5616
// / this code will break with a future version of Swift.
@@ -5850,13 +5727,8 @@ Expr *ExprRewriter::coerceCallArguments(
5850
5727
// FIXME: Eventually, we want to enforce that we have either argTuple or
5851
5728
// argParen here.
5852
5729
5853
- // Warn if there was a recent change in trailing closure binding semantics
5854
- // that might have lead to a silent change in behavior.
5855
- if (trailingClosureMatching == TrailingClosureMatching::Forward) {
5856
- maybeWarnAboutTrailingClosureBindingChange (
5857
- callee, apply ? apply->getFn () : nullptr , arg, args, params, paramInfo,
5858
- unlabeledTrailingClosureIndex, parameterBindings);
5859
- } else {
5730
+ // Warn about the backward scan being deprecated.
5731
+ if (trailingClosureMatching == TrailingClosureMatching::Backward) {
5860
5732
warnAboutTrailingClosureBackwardScan (
5861
5733
callee, apply ? apply->getFn () : nullptr , arg, params,
5862
5734
unlabeledTrailingClosureIndex, parameterBindings);
0 commit comments