Skip to content

Commit e7b0902

Browse files
committed
Sema: Don't visit elements of a BraceStmt twice when checking availability
1 parent d924349 commit e7b0902

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,14 @@ class StmtAvailabilityWalker : public ASTWalker {
29592959
explicit StmtAvailabilityWalker(ExportContext where)
29602960
: Where(where) {}
29612961

2962+
/// We'll visit each element of a BraceStmt individually.
2963+
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
2964+
if (isa<BraceStmt>(S))
2965+
return std::make_pair(false, S);
2966+
2967+
return std::make_pair(true, S);
2968+
}
2969+
29622970
/// We'll visit the expression from performSyntacticExprDiagnostics().
29632971
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
29642972
return std::make_pair(false, E);

test/attr/attr_inlinable.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func internalFunction() {}
1818
public func publicFunction() {}
1919

2020
private struct PrivateStruct {}
21-
// expected-note@-1 3{{struct 'PrivateStruct' is not '@usableFromInline' or public}}
22-
// expected-note@-2 {{initializer 'init()' is not '@usableFromInline' or public}}
21+
// expected-note@-1 5{{struct 'PrivateStruct' is not '@usableFromInline' or public}}
22+
// expected-note@-2 2{{initializer 'init()' is not '@usableFromInline' or public}}
2323
struct InternalStruct {}
2424
// expected-note@-1 3{{struct 'InternalStruct' is not '@usableFromInline' or public}}
2525
// expected-note@-2 {{initializer 'init()' is not '@usableFromInline' or public}}
@@ -350,3 +350,10 @@ public struct PrivateInlinableCrash {
350350
// expected-error@-1 {{'@inlinable' attribute cannot be applied to stored properties}}
351351
}
352352

353+
@inlinable public func nestedBraceStmtTest() {
354+
if true {
355+
let _: PrivateStruct = PrivateStruct()
356+
// expected-error@-1 2{{struct 'PrivateStruct' is private and cannot be referenced from an '@inlinable' function}}
357+
// expected-error@-2 {{initializer 'init()' is private and cannot be referenced from an '@inlinable' function}}
358+
}
359+
}

0 commit comments

Comments
 (0)