diff --git a/lib/Basic/StringExtras.cpp b/lib/Basic/StringExtras.cpp index 4810a0ca401..51f8970dffc 100644 --- a/lib/Basic/StringExtras.cpp +++ b/lib/Basic/StringExtras.cpp @@ -1301,6 +1301,15 @@ bool swift::omitNeedlessWords(StringRef &baseName, splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName)) anyChanges = true; + // For a method imported as "async", drop the "Asynchronously" suffix from + // the base name. It is redundant with 'async'. + const StringRef asynchronously = "Asynchronously"; + if (isAsync && camel_case::getLastWord(baseName) == asynchronously && + baseName.size() > asynchronously.size()) { + baseName = baseName.drop_back(asynchronously.size()); + anyChanges = true; + } + // Omit needless words based on parameter types. for (unsigned i = 0, n = argNames.size(); i != n; ++i) { // If there is no corresponding parameter, there is nothing to diff --git a/test/ClangImporter/objc_async.swift b/test/ClangImporter/objc_async.swift index 018c3a64eee..8d2e691d498 100644 --- a/test/ClangImporter/objc_async.swift +++ b/test/ClangImporter/objc_async.swift @@ -20,6 +20,7 @@ func testSlowServer(slowServer: SlowServer) async throws { // expected-error@-1{{call is 'async' but is not marked with 'await'}} let _: String? = await try slowServer.fortune() + let _: Int = await try slowServer.magicNumber(withSeed: 42) } func testSlowServerSynchronous(slowServer: SlowServer) { diff --git a/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h b/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h index 5a4da7ccf0d..b968a5561e7 100644 --- a/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h +++ b/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h @@ -10,7 +10,8 @@ -(void)findAnswerAsynchronously:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswer(completionHandler:)"))); -(BOOL)findAnswerFailinglyWithError:(NSError * _Nullable * _Nullable)error completion:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswerFailingly(completionHandler:)"))); -(void)doSomethingFun:(NSString *)operation then:(void (^)(void))completionHandler; --(void)getFortuneWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler; +-(void)getFortuneAsynchronouslyWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler; +-(void)getMagicNumberAsynchronouslyWithSeed:(NSInteger)seed completionHandler:(void (^)(NSInteger, NSError * _Nullable))handler; @property(readwrite) void (^completionHandler)(NSInteger); -(void)doSomethingConflicted:(NSString *)operation completionHandler:(void (^)(NSInteger))handler;