Skip to content

Commit f515836

Browse files
Merge pull request swiftlang#26141 from devincoughlin/unavailable-extension-of-unavailable-in-pound-if
[Sema] Allow unavailable extension of unavailable type in #if
2 parents 62a37d7 + b45d91d commit f515836

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,13 @@ static const Decl *findContainingDeclaration(SourceRange ReferenceRange,
860860
auto ContainsReferenceRange = [&](const Decl *D) -> bool {
861861
if (ReferenceRange.isInvalid())
862862
return false;
863+
864+
// Members of an active #if are represented both inside the
865+
// IfConfigDecl and in the enclosing context. Skip over the IfConfigDecl
866+
// so that that the member declaration is found rather the #if itself.
867+
if (isa<IfConfigDecl>(D))
868+
return false;
869+
863870
return SM.rangeContains(D->getSourceRange(), ReferenceRange);
864871
};
865872

test/attr/attr_availability_osx.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,14 @@ extension TestStruct {
198198
introducedInExtensionMacOS()
199199
}
200200
}
201+
202+
@available(macOS, unavailable)
203+
struct UnavailableStruct { }
204+
205+
@available(macOS, unavailable)
206+
extension UnavailableStruct { } // no-error
207+
208+
#if os(macOS)
209+
@available(macOS, unavailable)
210+
extension UnavailableStruct { } // no-error
211+
#endif

0 commit comments

Comments
 (0)