Skip to content

[3.0 compat] Don't diagnose @escaping var-arg closures. #5217

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
Oct 11, 2016
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
10 changes: 9 additions & 1 deletion lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,8 +2002,16 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
// Handle @escaping
if (hasFunctionAttr && ty->is<FunctionType>()) {
if (attrs.has(TAK_escaping)) {
// For compatibility with 3.0, we don't emit an error if it appears on a
// variadic argument list.
//
// FIXME: Version-gate on Swift language version 3, as we don't want its
// presence to confuse users.
bool skipDiagnostic = isVariadicFunctionParam;

// The attribute is meaningless except on parameter types.
if (!isFunctionParam) {
bool shouldDiagnose = !isFunctionParam && !skipDiagnostic;
if (shouldDiagnose) {
auto &SM = TC.Context.SourceMgr;
auto loc = attrs.getLoc(TAK_escaping);
auto attrRange = SourceRange(
Expand Down
5 changes: 5 additions & 0 deletions test/attr/attr_escaping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func takesVarargsOfFunctions(fns: () -> ()...) {
}
}

// This is allowed, in order to keep source compat with Swift version 3.0.
//
// FIXME: version-gate on Swift version 3
func takesVarargsOfFunctionsExplicitEscaping(fns: @escaping () -> ()...) {}

func takesNoEscapeFunction(fn: () -> ()) { // expected-note {{parameter 'fn' is implicitly non-escaping}}
takesVarargsOfFunctions(fns: fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
}
Expand Down