Skip to content

Commit 01b5b6a

Browse files
hartbitjrose-apple
authored andcommitted
[SR-4205] Removed the non_trailing_closure_before_default_args warning (#8033)
rdar://problem/21193574 says that this warning dates back to when closure args before default args used to be considered as trailing closures. This is not the case anymore so Jordan suggested we remove the warning.
1 parent c618f19 commit 01b5b6a

File tree

5 files changed

+4
-54
lines changed

5 files changed

+4
-54
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,6 @@ WARNING(function_type_access_warn,none,
12361236
"because its %select{parameter|result}5 uses "
12371237
"%select{a private|a fileprivate|an internal|%error|%error}3 type",
12381238
(bool, Accessibility, bool, Accessibility, unsigned, bool))
1239-
WARNING(non_trailing_closure_before_default_args,none,
1240-
"closure parameter prior to parameters with default arguments will "
1241-
"not be treated as a trailing closure", ())
12421239
ERROR(noreturn_not_supported,none,
12431240
"'@noreturn' has been removed; functions that never return should have a "
12441241
"return type of 'Never' instead", ())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,43 +5041,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
50415041
makeFinal(TC.Context, FD);
50425042
}
50435043
}
5044-
5045-
// Check whether we have parameters with default arguments that follow a
5046-
// closure parameter; warn about such things, because the closure will not
5047-
// be treated as a trailing closure.
5048-
if (!FD->isImplicit()) {
5049-
auto paramList = FD->getParameterList(FD->getImplicitSelfDecl() ? 1 : 0);
5050-
bool anyDefaultArguments = false;
5051-
for (unsigned i = paramList->size(); i != 0; --i) {
5052-
// Determine whether the parameter is of (possibly lvalue, possibly
5053-
// optional), non-autoclosure function type, which could receive a
5054-
// closure. We look at the type sugar directly, so that one can
5055-
// suppress this warning by adding parentheses.
5056-
auto &param = paramList->get(i-1);
5057-
auto paramType = param->getType();
5058-
5059-
if (auto *funcTy = isUnparenthesizedTrailingClosure(paramType)) {
5060-
// If we saw any default arguments before this, complain.
5061-
// This doesn't apply to autoclosures.
5062-
if (anyDefaultArguments && !funcTy->getExtInfo().isAutoClosure()) {
5063-
TC.diagnose(param->getStartLoc(),
5064-
diag::non_trailing_closure_before_default_args)
5065-
.highlight(param->getSourceRange());
5066-
}
5067-
5068-
break;
5069-
}
5070-
5071-
// If we have a default argument, keep going.
5072-
if (param->isDefaultArgument()) {
5073-
anyDefaultArguments = true;
5074-
continue;
5075-
}
5076-
5077-
// We're done.
5078-
break;
5079-
}
5080-
}
50815044
}
50825045

50835046
void visitModuleDecl(ModuleDecl *) { }

test/attr/attr_noescape.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ func r19763676Caller(_ g: @noescape (Int) -> Int) { // expected-warning{{@noesca
213213

214214

215215
// <rdar://problem/19763732> False positive in @noescape analysis triggered by default arguments
216-
func calleeWithDefaultParameters(_ f: @noescape () -> (), x : Int = 1) {} // expected-warning {{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
217-
// expected-warning@-1{{@noescape is the default and is deprecated}} {{39-49=}}
218-
216+
func calleeWithDefaultParameters(_ f: @noescape () -> (), x : Int = 1) {} // expected-warning{{@noescape is the default and is deprecated}} {{39-49=}}
219217
func callerOfDefaultParams(_ g: @noescape () -> ()) { // expected-warning{{@noescape is the default and is deprecated}} {{33-43=}}
220218
calleeWithDefaultParameters(g)
221219
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
// Warn about non-trailing closures followed by parameters with
3+
// SR-4205: Don't warn about non-trailing closures followed by parameters with
44
// default arguments.
5-
func f1(_ f: () -> (), bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
6-
func f2(_ f: (() -> ())!, bar: Int = 10, wibble: Int = 17) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
7-
func f3(_ f: (() -> ())?, bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
8-
9-
// An extra set of parentheses suppresses the warning.
10-
func g1(_ f: (() -> ()), bar: Int = 10) { } // no-warning
11-
12-
// Stop at the first closure.
13-
func g2(_ f: () -> (), g: (() -> ())? = nil) { } // no-warning
5+
func f1(_ f: () -> (), bar: Int = 10) { } // no-warning

test/expr/closure/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var func6 : (_ fn : (Int,Int) -> Int) -> ()
44
var func6a : ((Int, Int) -> Int) -> ()
55
var func6b : (Int, (Int, Int) -> Int) -> ()
6-
func func6c(_ f: (Int, Int) -> Int, _ n: Int = 0) {} // expected-warning{{prior to parameters}}
6+
func func6c(_ f: (Int, Int) -> Int, _ n: Int = 0) {}
77

88

99
// Expressions can be auto-closurified, so that they can be evaluated separately

0 commit comments

Comments
 (0)