Skip to content

Commit f536a58

Browse files
committed
[Sema] Silence an inconsistent availability error for the stdlib
Don't raise the error availability_decl_more_than_enclosing in the context is unavailable and if read in a swiftinterface file. This error was present in the stdlib in 5.3 without side effects so we still want to accept it.
1 parent 25c9ddd commit f536a58

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,16 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
15301530
VersionRange::allGTE(attr->Introduced.getValue())};
15311531

15321532
if (!AttrRange.isContainedIn(EnclosingAnnotatedRange.getValue())) {
1533-
diagnose(attr->getLocation(), diag::availability_decl_more_than_enclosing);
1534-
diagnose(EnclosingDecl->getLoc(),
1535-
diag::availability_decl_more_than_enclosing_enclosing_here);
1533+
// Don't show this error in swiftinterfaces if it is about a context that
1534+
// is unavailable, this was in the stdlib at Swift 5.3.
1535+
SourceFile *Parent = D->getDeclContext()->getParentSourceFile();
1536+
if (!Parent || Parent->Kind != SourceFileKind::Interface ||
1537+
!EnclosingAnnotatedRange.getValue().isKnownUnreachable()) {
1538+
diagnose(attr->getLocation(),
1539+
diag::availability_decl_more_than_enclosing);
1540+
diagnose(EnclosingDecl->getLoc(),
1541+
diag::availability_decl_more_than_enclosing_enclosing_here);
1542+
}
15361543
}
15371544
}
15381545

0 commit comments

Comments
 (0)