Skip to content

Commit c6d5c84

Browse files
authored
Merge pull request #26589 from xymus/dont-inherit-clang-availability
Don't apply the unavailability of an extension to members imported from Clang
2 parents 84d7b60 + 6fe7345 commit c6d5c84

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

lib/AST/Attr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,15 @@ const AvailableAttr *AvailableAttr::isUnavailable(const Decl *D) {
10731073
return attr;
10741074

10751075
// If D is an extension member, check if the extension is unavailable.
1076-
if (auto ext = dyn_cast<ExtensionDecl>(D->getDeclContext()))
1077-
return AvailableAttr::isUnavailable(ext);
1076+
//
1077+
// Skip decls imported from Clang, they could be associated to the wrong
1078+
// extension and inherit undesired unavailability. The ClangImporter
1079+
// associates Objective-C protocol members to the first category where the
1080+
// protocol is directly or indirectly adopted, no matter its availability
1081+
// and the availability of other categories. rdar://problem/53956555
1082+
if (!D->getClangNode())
1083+
if (auto ext = dyn_cast<ExtensionDecl>(D->getDeclContext()))
1084+
return AvailableAttr::isUnavailable(ext);
10781085

10791086
return nullptr;
10801087
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface SharedInterface
4+
@end
5+
6+
@protocol SharedProtocol <NSObject>
7+
+ (NSInteger)foo;
8+
@end
9+
10+
// ClangImporter imports the first category as the extension parent of
11+
// SharedInterface.foo, making foo unavailable on macOS when the extension
12+
// unavailability is inherited by its members.
13+
API_UNAVAILABLE(macos)
14+
@interface SharedInterface (IOSCategory) <SharedProtocol>
15+
@end
16+
17+
API_UNAVAILABLE(ios)
18+
@interface SharedInterface (MacOSCategory) <SharedProtocol>
19+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/availability_platform_categories.h
2+
3+
// REQUIRES: OS=macos
4+
5+
// Test when a function is associated to an Objective-C category with the
6+
// wrong unavailability. rdar://problem/53956555
7+
8+
print(SharedInterface.foo())

0 commit comments

Comments
 (0)