Skip to content

Commit bb82157

Browse files
authored
Merge pull request #36108 from CodaFi/ex-tension
[5.4] Narrowly Fix a Crash in Availability Checking of Defer Bodies
2 parents cdfb483 + 495c822 commit bb82157

File tree

4 files changed

+18
-44
lines changed

4 files changed

+18
-44
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ static void computeExportContextBits(ASTContext &Ctx, Decl *D,
147147
if (D->isSPI())
148148
*spi = true;
149149

150-
// Defer bodies are desugared to an implicit closure expression. We need to
151-
// dilute the meaning of "implicit" to make sure we're still checking
152-
// availability inside of defer statements.
153-
const auto isDeferBody = isa<FuncDecl>(D) && cast<FuncDecl>(D)->isDeferBody();
154-
if (D->isImplicit() && !isDeferBody)
150+
if (D->isImplicit())
155151
*implicit = true;
156152

157153
if (D->getAttrs().getDeprecated(Ctx))
@@ -3282,7 +3278,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
32823278
bool swift::diagnoseTypeReprAvailability(const TypeRepr *T,
32833279
const ExportContext &where,
32843280
DeclAvailabilityFlags flags) {
3285-
if (!T)
3281+
if (!T || where.isImplicit())
32863282
return false;
32873283
TypeReprAvailabilityWalker walker(where, flags);
32883284
const_cast<TypeRepr*>(T)->walk(walker);

test/Sema/availability.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,3 @@ struct VarToFunc {
195195
}
196196
}
197197

198-
struct DeferBody {
199-
func foo() {
200-
enum No: Error {
201-
case no
202-
}
203-
204-
defer {
205-
do {
206-
throw No.no
207-
} catch No.no {
208-
} catch {
209-
}
210-
}
211-
_ = ()
212-
}
213-
214-
func bar() {
215-
@available(*, unavailable)
216-
enum No: Error { // expected-note 2 {{'No' has been explicitly marked unavailable here}}
217-
case no
218-
}
219-
do {
220-
throw No.no
221-
// expected-error@-1 {{'No' is unavailable}}
222-
} catch No.no {} catch _ {}
223-
// expected-error@-1 {{'No' is unavailable}}
224-
}
225-
}
226-

test/attr/attr_inlinable.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,3 @@ public struct PrivateInlinableCrash {
357357
// expected-error@-2 {{initializer 'init()' is private and cannot be referenced from an '@inlinable' function}}
358358
}
359359
}
360-
361-
// Just make sure we don't crash.
362-
private func deferBodyTestCall() {} // expected-note {{global function 'deferBodyTestCall()' is not '@usableFromInline' or public}}
363-
@inlinable public func deferBodyTest() {
364-
defer {
365-
deferBodyTestCall() // expected-error {{global function 'deferBodyTestCall()' is private and cannot be referenced from an '@inlinable' function}}
366-
}
367-
_ = ()
368-
}
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)