Skip to content

[SR-4205] Removed the non_trailing_closure_before_default_args warning #8033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,6 @@ WARNING(function_type_access_warn,none,
"because its %select{parameter|result}5 uses "
"%select{a private|a fileprivate|an internal|%error|%error}3 type",
(bool, Accessibility, bool, Accessibility, unsigned, bool))
WARNING(non_trailing_closure_before_default_args,none,
"closure parameter prior to parameters with default arguments will "
"not be treated as a trailing closure", ())
ERROR(noreturn_not_supported,none,
"'@noreturn' has been removed; functions that never return should have a "
"return type of 'Never' instead", ())
Expand Down
37 changes: 0 additions & 37 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5041,43 +5041,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
makeFinal(TC.Context, FD);
}
}

// Check whether we have parameters with default arguments that follow a
// closure parameter; warn about such things, because the closure will not
// be treated as a trailing closure.
if (!FD->isImplicit()) {
auto paramList = FD->getParameterList(FD->getImplicitSelfDecl() ? 1 : 0);
bool anyDefaultArguments = false;
for (unsigned i = paramList->size(); i != 0; --i) {
// Determine whether the parameter is of (possibly lvalue, possibly
// optional), non-autoclosure function type, which could receive a
// closure. We look at the type sugar directly, so that one can
// suppress this warning by adding parentheses.
auto &param = paramList->get(i-1);
auto paramType = param->getType();

if (auto *funcTy = isUnparenthesizedTrailingClosure(paramType)) {
// If we saw any default arguments before this, complain.
// This doesn't apply to autoclosures.
if (anyDefaultArguments && !funcTy->getExtInfo().isAutoClosure()) {
TC.diagnose(param->getStartLoc(),
diag::non_trailing_closure_before_default_args)
.highlight(param->getSourceRange());
}

break;
}

// If we have a default argument, keep going.
if (param->isDefaultArgument()) {
anyDefaultArguments = true;
continue;
}

// We're done.
break;
}
}
}

void visitModuleDecl(ModuleDecl *) { }
Expand Down
4 changes: 1 addition & 3 deletions test/attr/attr_noescape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ func r19763676Caller(_ g: @noescape (Int) -> Int) { // expected-warning{{@noesca


// <rdar://problem/19763732> False positive in @noescape analysis triggered by default arguments
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}}
// expected-warning@-1{{@noescape is the default and is deprecated}} {{39-49=}}

func calleeWithDefaultParameters(_ f: @noescape () -> (), x : Int = 1) {} // expected-warning{{@noescape is the default and is deprecated}} {{39-49=}}
func callerOfDefaultParams(_ g: @noescape () -> ()) { // expected-warning{{@noescape is the default and is deprecated}} {{33-43=}}
calleeWithDefaultParameters(g)
}
Expand Down
12 changes: 2 additions & 10 deletions test/decl/func/trailing_closures.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// RUN: %target-typecheck-verify-swift

// Warn about non-trailing closures followed by parameters with
// SR-4205: Don't warn about non-trailing closures followed by parameters with
// default arguments.
func f1(_ f: () -> (), bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
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}}
func f3(_ f: (() -> ())?, bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}

// An extra set of parentheses suppresses the warning.
func g1(_ f: (() -> ()), bar: Int = 10) { } // no-warning

// Stop at the first closure.
func g2(_ f: () -> (), g: (() -> ())? = nil) { } // no-warning
func f1(_ f: () -> (), bar: Int = 10) { } // no-warning
2 changes: 1 addition & 1 deletion test/expr/closure/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var func6 : (_ fn : (Int,Int) -> Int) -> ()
var func6a : ((Int, Int) -> Int) -> ()
var func6b : (Int, (Int, Int) -> Int) -> ()
func func6c(_ f: (Int, Int) -> Int, _ n: Int = 0) {} // expected-warning{{prior to parameters}}
func func6c(_ f: (Int, Int) -> Int, _ n: Int = 0) {}


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