Skip to content

Commit 495c822

Browse files
committed
Fix a Crash in Availability Checking of Defer Bodies
NIO exposed an issue in the new availability walkers where an implicit check was not being performed. They were able to get this to crash by using a defer statement - the body of which contains implicit declarations that got run through the walker. This exposed a wider hole in availability checking of defer statements. Namely, that it wasn't happening. This is a narrow fix (as opposed to the broader fix in #36102) that is safer to take for Swift 5.4. rdar://74484150
1 parent f08c7a8 commit 495c822

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,7 +3278,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
32783278
bool swift::diagnoseTypeReprAvailability(const TypeRepr *T,
32793279
const ExportContext &where,
32803280
DeclAvailabilityFlags flags) {
3281-
if (!T)
3281+
if (!T || where.isImplicit())
32823282
return false;
32833283
TypeReprAvailabilityWalker walker(where, flags);
32843284
const_cast<TypeRepr*>(T)->walk(walker);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -typecheck %s
2+
3+
func foo() {
4+
enum No: Error {
5+
case no
6+
}
7+
8+
defer {
9+
do {
10+
throw No.no
11+
} catch No.no {
12+
} catch {
13+
}
14+
}
15+
_ = ()
16+
}

0 commit comments

Comments
 (0)