Skip to content

Commit eb6e8a3

Browse files
author
ematejska
authored
Merge pull request #5217 from milseman/3_0_escaping
[3.0 compat] Don't diagnose @escaping var-arg closures.
2 parents 8832e5d + c6b6688 commit eb6e8a3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,16 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20022002
// Handle @escaping
20032003
if (hasFunctionAttr && ty->is<FunctionType>()) {
20042004
if (attrs.has(TAK_escaping)) {
2005+
// For compatibility with 3.0, we don't emit an error if it appears on a
2006+
// variadic argument list.
2007+
//
2008+
// FIXME: Version-gate on Swift language version 3, as we don't want its
2009+
// presence to confuse users.
2010+
bool skipDiagnostic = isVariadicFunctionParam;
2011+
20052012
// The attribute is meaningless except on parameter types.
2006-
if (!isFunctionParam) {
2013+
bool shouldDiagnose = !isFunctionParam && !skipDiagnostic;
2014+
if (shouldDiagnose) {
20072015
auto &SM = TC.Context.SourceMgr;
20082016
auto loc = attrs.getLoc(TAK_escaping);
20092017
auto attrRange = SourceRange(

test/attr/attr_escaping.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func takesVarargsOfFunctions(fns: () -> ()...) {
139139
}
140140
}
141141

142+
// This is allowed, in order to keep source compat with Swift version 3.0.
143+
//
144+
// FIXME: version-gate on Swift version 3
145+
func takesVarargsOfFunctionsExplicitEscaping(fns: @escaping () -> ()...) {}
146+
142147
func takesNoEscapeFunction(fn: () -> ()) { // expected-note {{parameter 'fn' is implicitly non-escaping}}
143148
takesVarargsOfFunctions(fns: fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
144149
}

0 commit comments

Comments
 (0)