Skip to content

Commit 888136f

Browse files
authored
Merge pull request #4242 from jrose-apple/swift-3-fix-all-the-escapings
Provide the '@escaping' fix-it for any call-site escaping mismatch.
2 parents 03668ee + 9b2a0f6 commit 888136f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,19 +3664,15 @@ static bool tryDiagnoseNonEscapingParameterToEscaping(Expr *expr, Type srcType,
36643664
// Need to be referencing a parameter of function type
36653665
auto declRef = dyn_cast<DeclRefExpr>(expr);
36663666
if (!declRef || !isa<ParamDecl>(declRef->getDecl()) ||
3667-
!declRef->getType()->is<FunctionType>())
3667+
!declRef->getType()->is<AnyFunctionType>())
36683668
return false;
36693669

36703670
// Must be from non-escaping function to escaping function
3671-
auto srcFT = srcType->getAs<FunctionType>();
3672-
auto destFT = dstType->getAs<FunctionType>();
3671+
auto srcFT = srcType->getAs<AnyFunctionType>();
3672+
auto destFT = dstType->getAs<AnyFunctionType>();
36733673
if (!srcFT || !destFT || !srcFT->isNoEscape() || destFT->isNoEscape())
36743674
return false;
36753675

3676-
// Function types must be equivalent modulo @escaping, @convention, etc.
3677-
if (!destFT->isEqual(srcFT->withExtInfo(destFT->getExtInfo())))
3678-
return false;
3679-
36803676
// Pick a specific diagnostic for the specific use
36813677
auto paramDecl = cast<ParamDecl>(declRef->getDecl());
36823678
switch (CS->getContextualTypePurpose()) {

test/attr/attr_escaping.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,24 @@ func callEscapingAutoclosureWithNoEscape_3(_ fn: @autoclosure () -> Int) {
7171
}
7272

7373

74+
func takesEscapingGeneric<T>(_ fn: @escaping () -> T) {}
75+
func callEscapingGeneric<T>(_ fn: () -> T) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{35-35=@escaping }}
76+
takesEscapingGeneric(fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
77+
}
78+
79+
80+
class Super {}
81+
class Sub: Super {}
82+
83+
func takesEscapingSuper(_ fn: @escaping () -> Super) {}
84+
func callEscapingSuper(_ fn: () -> Sub) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{30-30=@escaping }}
85+
takesEscapingSuper(fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
86+
}
87+
88+
func takesEscapingSuperGeneric<T: Super>(_ fn: @escaping () -> T) {}
89+
func callEscapingSuperGeneric(_ fn: () -> Sub) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{37-37=@escaping }}
90+
takesEscapingSuperGeneric(fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
91+
}
92+
func callEscapingSuperGeneric<T: Sub>(_ fn: () -> T) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{45-45=@escaping }}
93+
takesEscapingSuperGeneric(fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
94+
}

0 commit comments

Comments
 (0)