Skip to content

Commit 71e0b1d

Browse files
committed
[Clang importer] Don't suppress properties due to async method imports.
The Clang importer had some logic to suppress the import of a property that had the same name as a method with no parameters. This logic inadvertently meant that an async import of a completion-handler method could prevent a (non-async) property of the same name to not be imported, breaking existing code. In such cases, don't suppress the property import. Fixes rdar://73326019.
1 parent e4986a3 commit 71e0b1d

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,11 @@ namespace {
21772177
if (!fd->getName().getArgumentNames().empty())
21782178
continue;
21792179

2180+
// async methods don't conflict with properties because of sync/async
2181+
// overloading.
2182+
if (fd->hasAsync())
2183+
continue;
2184+
21802185
foundMethod = true;
21812186
} else if (auto *var = dyn_cast<VarDecl>(result)) {
21822187
if (var->isInstanceMember() != decl->isInstanceProperty())

test/ClangImporter/objc_async.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func testSlowServer(slowServer: SlowServer) async throws {
4646
slowServer.repeatTrick("jump") // expected-error{{missing argument for parameter 'completionHandler' in call}}
4747

4848
_ = try await slowServer.someAsyncMethod()
49+
50+
51+
_ = await slowServer.operations()
4952
}
5053

5154
func testSlowServerSynchronous(slowServer: SlowServer) {
@@ -57,6 +60,9 @@ func testSlowServerSynchronous(slowServer: SlowServer) {
5760
slowServer.dance("jig") { s in print(s + "") }
5861
slowServer.leap(17) { s in print(s + "") }
5962
slowServer.repeatTrick("jump") { i in print(i + 1) }
63+
64+
let s = slowServer.operations
65+
_ = s + []
6066
}
6167

6268
func testSlowServerOldSchool(slowServer: SlowServer) {

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
5757
-(void)oldAPIWithCompletionHandler:(void (^ _Nonnull)(NSString *_Nullable, NSError *_Nullable))handler __attribute__((availability(macosx, deprecated=10.14)));
5858

5959
-(void)someAsyncMethodWithBlock:(void (^ _Nonnull)(NSString *_Nullable, NSError *_Nullable))completionHandler;
60+
61+
// Property & async method overloading
62+
-(void)getOperationsWithCompletionHandler:(void (^)(NSArray<NSString *> *))handler;
63+
@property (readonly, nonatomic) NSArray<NSString *> *operations;
6064
@end
6165

6266
@protocol RefrigeratorDelegate<NSObject>

0 commit comments

Comments
 (0)