Skip to content

Commit d249b5c

Browse files
committed
[Clang importer] Make sure we mirror protocol decls for all names.
When mirroring declarations from protocols, make sure to mirror for all potential imported names. Otherwise, we might miss out on one or the other of an async import or a completion-handler import of the same method. Fixes rdar://71429577.
1 parent 95edef7 commit d249b5c

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7459,14 +7459,15 @@ void SwiftDeclConverter::importNonOverriddenMirroredMethods(DeclContext *dc,
74597459

74607460
// Import the method.
74617461
auto proto = entries[i].second;
7462-
if (auto imported =
7463-
Impl.importMirroredDecl(objcMethod, dc, getVersion(), proto)) {
7464-
members.push_back(imported);
7465-
7466-
for (auto alternate : Impl.getAlternateDecls(imported))
7467-
if (imported->getDeclContext() == alternate->getDeclContext())
7468-
members.push_back(alternate);
7469-
}
7462+
Impl.forEachDistinctName(objcMethod,
7463+
[&](ImportedName name, ImportNameVersion version) {
7464+
if (auto imported =
7465+
Impl.importMirroredDecl(objcMethod, dc, version, proto)) {
7466+
if (imported->getDeclContext() == dc)
7467+
members.push_back(imported);
7468+
}
7469+
return true;
7470+
});
74707471
}
74717472
}
74727473

test/ClangImporter/objc_async.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func testSlowServer(slowServer: SlowServer) async throws {
2525

2626
await slowServer.serverRestart("localhost")
2727
await slowServer.server("localhost", atPriorityRestart: 0.8)
28+
29+
_ = await slowServer.allOperations()
2830
}
2931

3032
func testSlowServerSynchronous(slowServer: SlowServer) {
@@ -36,4 +38,6 @@ func testSlowServerOldSchool(slowServer: SlowServer) {
3638
slowServer.doSomethingSlow("mail") { i in
3739
_ = i
3840
}
41+
42+
_ = slowServer.allOperations
3943
}

test/IDE/print_clang_objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// REQUIRES: objc_interop
77
// REQUIRES: concurrency
88

9-
// CHECK-LABEL: class SlowServer : NSObject {
9+
// CHECK-LABEL: class SlowServer : NSObject, ServiceProvider {
1010
// CHECK-DAG: func doSomethingSlow(_ operation: String, completionHandler handler: @escaping (Int) -> Void)
1111
// CHECK-DAG: func doSomethingSlow(_ operation: String) async -> Int
1212
// CHECK-DAG: func doSomethingDangerous(_ operation: String, completionHandler handler: ((String?, Error?) -> Void)? = nil)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
#pragma clang assume_nonnull begin
55

6-
@interface SlowServer : NSObject
6+
@protocol ServiceProvider
7+
@property(readonly) NSArray<NSString *> *allOperations;
8+
-(void)allOperationsWithCompletionHandler:(void (^)(NSArray<NSString *> *))completion;
9+
@end
10+
11+
@interface SlowServer : NSObject <ServiceProvider>
712
-(void)doSomethingSlow:(NSString *)operation completionHandler:(void (^)(NSInteger))handler;
813
-(void)doSomethingDangerous:(NSString *)operation completionHandler:(void (^ _Nullable)(NSString *_Nullable, NSError * _Nullable))handler;
914
-(void)checkAvailabilityWithCompletionHandler:(void (^)(BOOL isAvailable))completionHandler;

0 commit comments

Comments
 (0)