Skip to content

Commit 2cb6cdc

Browse files
authored
Merge pull request swiftlang#28886 from DougGregor/objc_direct
2 parents 6508604 + 35a1906 commit 2cb6cdc

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7555,6 +7555,15 @@ void ClangImporter::Implementation::importAttributes(
75557555
}
75567556
}
75577557

7558+
if (auto method = dyn_cast<clang::ObjCMethodDecl>(ClangDecl)) {
7559+
if (method->isDirectMethod() && !AnyUnavailable) {
7560+
auto attr = AvailableAttr::createPlatformAgnostic(
7561+
C, "", "", PlatformAgnosticAvailabilityKind::UnavailableInSwift);
7562+
MappedDecl->getAttrs().add(attr);
7563+
AnyUnavailable = true;
7564+
}
7565+
}
7566+
75587567
// If the declaration is unavailable, we're done.
75597568
if (AnyUnavailable)
75607569
return;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@interface Bar
2+
@property (readonly, direct, nonatomic) int directProperty;
3+
- (void)directMethod __attribute__((objc_direct));
4+
+ (void)directClassMethod __attribute__((objc_direct));
5+
@end
6+
7+
__attribute__((objc_direct_members))
8+
@interface Bar ()
9+
@property (readonly, nonatomic) int directProperty2;
10+
- (void)directMethod2;
11+
+ (void)directClassMethod2;
12+
@end

test/ClangImporter/objc_direct.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend-verify -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/objc_direct.h -verify-ignore-unknown
2+
3+
// REQUIRES: objc_interop
4+
5+
func callThingsOnBar(_ x: Bar) {
6+
let _ = x.directProperty // expected-error {{getter for 'directProperty' is unavailable in Swift}}
7+
let _ = x.directProperty2 // expected-error {{getter for 'directProperty2' is unavailable in Swift}}
8+
9+
x.directMethod() // expected-error {{'directMethod()' is unavailable in Swift}}
10+
x.directMethod2() // expected-error {{'directMethod2()' is unavailable in Swift}}
11+
12+
Bar.directClassMethod() // expected-error {{'directClassMethod()' is unavailable in Swift}}
13+
Bar.directClassMethod2() // expected-error {{'directClassMethod2()' is unavailable in Swift}}
14+
}

0 commit comments

Comments
 (0)