Skip to content

Commit 22df0dd

Browse files
committed
Partially revert “Don’t declare async methods with alternatives in headers”
This reverts parts of commit d4ee34c. Specifically, it reverts the implementation, implements a different workaround for the bug, and modifies the test to pass if the workaround is effective. Fixes rdar://97810819.
1 parent 395997b commit 22df0dd

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,31 +2019,12 @@ auto DeclAndTypePrinter::getImpl() -> Implementation {
20192019
return Implementation(os, *this, outputLang);
20202020
}
20212021

2022-
static bool isAsyncAlternativeOfOtherDecl(const ValueDecl *VD) {
2023-
auto AFD = dyn_cast<AbstractFunctionDecl>(VD);
2024-
if (!AFD || !AFD->isAsyncContext() || !AFD->getObjCSelector())
2025-
return false;
2026-
2027-
auto type = AFD->getDeclContext()->getSelfNominalTypeDecl();
2028-
if (!type)
2029-
return false;
2030-
auto others = type->lookupDirect(AFD->getObjCSelector(),
2031-
AFD->isInstanceMember());
2032-
2033-
for (auto other : others)
2034-
if (other->getAsyncAlternative() == AFD)
2035-
return true;
2036-
2037-
return false;
2038-
}
2039-
20402022
bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {
20412023
return !VD->isInvalid() &&
20422024
(outputLang == OutputLanguageMode::Cxx
20432025
? cxx_translation::isVisibleToCxx(VD, minRequiredAccess)
20442026
: isVisibleToObjC(VD, minRequiredAccess)) &&
2045-
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>() &&
2046-
!isAsyncAlternativeOfOtherDecl(VD);
2027+
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>();
20472028
}
20482029

20492030
void DeclAndTypePrinter::print(const Decl *D) {

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
8080
"# include <swift/objc-prologue.h>\n"
8181
"#endif\n"
8282
"\n"
83+
"#pragma clang diagnostic ignored \"-Wduplicate-method-match\"\n"
8384
"#pragma clang diagnostic ignored \"-Wauto-import\"\n";
8485
emitObjCConditional(out,
8586
[&] { out << "#include <Foundation/Foundation.h>\n"; });

test/PrintAsObjC/protocols.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import objc_generics
2828
@objc protocol B : A, Sendable {}
2929

3030
// CHECK-LABEL: @protocol CompletionAndAsync
31+
// FIXME: We should detect this duplication.
32+
// CHECK-NEXT: - (void)helloWithCompletion:(void (^ _Nonnull)(BOOL))completionHandler SWIFT_AVAILABILITY
3133
// CHECK-NEXT: - (void)helloWithCompletion:(void (^ _Nonnull)(BOOL))completion;
3234
// CHECK-NEXT: @end
3335
@objc protocol CompletionAndAsync {

0 commit comments

Comments
 (0)