Skip to content

Commit fc81cd0

Browse files
authored
Merge pull request #10353 from slavapestov/autoclosure-or-not-still-non-escaping
Sema: Fix historical quirk with @escaping diagnostics
2 parents e9de363 + a6339be commit fc81cd0

File tree

7 files changed

+7
-22
lines changed

7 files changed

+7
-22
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,9 +2701,6 @@ NOTE(silence_optional_in_interpolation_segment_call,none,
27012701
ERROR(invalid_noescape_use,none,
27022702
"non-escaping %select{value|parameter}1 %0 may only be called",
27032703
(Identifier, bool))
2704-
NOTE(noescape_autoclosure,none,
2705-
"parameter %0 is implicitly non-escaping because it was declared @autoclosure",
2706-
(Identifier))
27072704
NOTE(noescape_parameter,none,
27082705
"parameter %0 is implicitly non-escaping",
27092706
(Identifier))

include/swift/Migrator/FixitFilter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ struct FixitFilter {
113113
Info.ID == diag::parameter_extraneous_double_up.ID ||
114114
Info.ID == diag::attr_decl_attr_now_on_type.ID ||
115115
Info.ID == diag::noescape_parameter.ID ||
116-
Info.ID == diag::noescape_autoclosure.ID ||
117116
Info.ID == diag::where_inside_brackets.ID ||
118117
Info.ID == diag::selector_construction_suggest.ID ||
119118
Info.ID == diag::selector_literal_deprecated_suggest.ID ||

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,8 +3852,7 @@ static bool tryDiagnoseNonEscapingParameterToEscaping(Expr *expr, Type srcType,
38523852

38533853
// Give a note and fixit
38543854
InFlightDiagnostic note = CS->TC.diagnose(
3855-
paramDecl->getLoc(), srcFT->isAutoClosure() ? diag::noescape_autoclosure
3856-
: diag::noescape_parameter,
3855+
paramDecl->getLoc(), diag::noescape_parameter,
38573856
paramDecl->getName());
38583857

38593858
if (!srcFT->isAutoClosure()) {

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,12 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
474474

475475
// If we're a parameter, emit a helpful fixit to add @escaping
476476
auto paramDecl = dyn_cast<ParamDecl>(DRE->getDecl());
477-
auto isAutoClosure = AFT->isAutoClosure();
478-
if (paramDecl && !isAutoClosure) {
477+
if (paramDecl) {
479478
TC.diagnose(paramDecl->getStartLoc(), diag::noescape_parameter,
480479
paramDecl->getName())
481480
.fixItInsert(paramDecl->getTypeLoc().getSourceRange().Start,
482481
"@escaping ");
483-
} else if (isAutoClosure)
484-
// TODO: add in a fixit for autoclosure
485-
TC.diagnose(DRE->getDecl()->getLoc(), diag::noescape_autoclosure,
486-
paramDecl->getName());
482+
}
487483
}
488484

489485
// Swift 3 mode produces a warning + Fix-It for the missing ".self"

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,11 @@ class FindCapturedVars : public ASTWalker {
211211

212212
// If we're a parameter, emit a helpful fixit to add @escaping
213213
auto paramDecl = dyn_cast<ParamDecl>(VD);
214-
bool isAutoClosure =
215-
VD->getInterfaceType()->castTo<AnyFunctionType>()->isAutoClosure();
216-
if (paramDecl && !isAutoClosure) {
214+
if (paramDecl) {
217215
TC.diagnose(paramDecl->getStartLoc(), diag::noescape_parameter,
218216
paramDecl->getName())
219217
.fixItInsert(paramDecl->getTypeLoc().getSourceRange().Start,
220218
"@escaping ");
221-
} else if (isAutoClosure) {
222-
// TODO: add in a fixit for autoclosure
223-
TC.diagnose(VD->getLoc(), diag::noescape_autoclosure,
224-
paramDecl->getName());
225219
}
226220
}
227221
}

test/attr/attr_autoclosure.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func overloadedEach<P: P2>(_ source: P, _ closure: @escaping () -> ()) {
5555
struct S : P2 {
5656
typealias Element = Int
5757
func each(_ closure: @autoclosure () -> ()) {
58-
// expected-note@-1{{parameter 'closure' is implicitly non-escaping because it was declared @autoclosure}}
58+
// expected-note@-1{{parameter 'closure' is implicitly non-escaping}}
5959

6060
overloadedEach(self, closure) // expected-error {{passing non-escaping parameter 'closure' to function expecting an @escaping closure}}
6161
}
@@ -93,7 +93,7 @@ class Sub : Super {
9393
func func12_sink(_ x: @escaping () -> Int) { }
9494

9595
func func12a(_ x: @autoclosure () -> Int) {
96-
// expected-note@-1{{parameter 'x' is implicitly non-escaping because it was declared @autoclosure}}
96+
// expected-note@-1{{parameter 'x' is implicitly non-escaping}}
9797

9898
func12_sink(x) // expected-error {{passing non-escaping parameter 'x' to function expecting an @escaping closure}}
9999
}

test/attr/attr_noescape.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func takeNoEscapeTest2(_ fn : @noescape () -> ()) { // expected-warning{{@noesc
170170

171171
// Autoclosure implies noescape, but produce nice diagnostics so people know
172172
// why noescape problems happen.
173-
func testAutoclosure(_ a : @autoclosure () -> Int) { // expected-note{{parameter 'a' is implicitly non-escaping because it was declared @autoclosure}}
173+
func testAutoclosure(_ a : @autoclosure () -> Int) { // expected-note{{parameter 'a' is implicitly non-escaping}}
174174
doesEscape { a() } // expected-error {{closure use of non-escaping parameter 'a' may allow it to escape}}
175175
}
176176

0 commit comments

Comments
 (0)