Skip to content

Commit 7efb6e9

Browse files
committed
Revert "Allow same-selector async/completion requirements"
This reverts commit 4c5c674.
1 parent 0b1d3df commit 7efb6e9

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,16 +1699,6 @@ NominalTypeDecl::lookupDirect(ObjCSelector selector, bool isInstance) {
16991699
return stored.Methods;
17001700
}
17011701

1702-
/// Is the new method an async alternative of any existing method, or vice
1703-
/// versa?
1704-
static bool isAnAsyncAlternative(AbstractFunctionDecl *newDecl,
1705-
llvm::TinyPtrVector<AbstractFunctionDecl *> &vec) {
1706-
return llvm::any_of(vec, [&](AbstractFunctionDecl *oldDecl) {
1707-
return newDecl->getAsyncAlternative(/*isKnownObjC=*/true) == oldDecl
1708-
|| oldDecl->getAsyncAlternative(/*isKnownObjC=*/true) == newDecl;
1709-
});
1710-
}
1711-
17121702
void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
17131703
ObjCSelector selector) {
17141704
if (!ObjCMethodLookup && !createObjCMethodLookup())
@@ -1726,7 +1716,7 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
17261716
if (auto *sf = method->getParentSourceFile()) {
17271717
if (vec.empty()) {
17281718
sf->ObjCMethodList.push_back(method);
1729-
} else if (!isa<ProtocolDecl>(this) || !isAnAsyncAlternative(method, vec)) {
1719+
} else {
17301720
// We have a conflict.
17311721
sf->ObjCMethodConflicts.insert({ this, selector, isInstanceMethod });
17321722
}

test/ClangImporter/objc_async_conformance.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,6 @@ class SelectorOK2 : NSObject, RequiredObserverOnlyCompletion {
6363
@nonobjc func hello(_ completion : @escaping (Bool) -> Void) -> Void { completion(true) }
6464
}
6565

66-
// can declare an @objc protocol with both selectors...
67-
@objc protocol SelectorBothAsyncProto {
68-
@objc(helloWithCompletion:)
69-
func hello() async -> Bool
70-
71-
@available(*, renamed: "hello()")
72-
@objc(helloWithCompletion:)
73-
func hello(completion: @escaping (Bool) -> Void)
74-
}
75-
76-
// and conform by implementing either one...
77-
class SelectorBothAsync1: NSObject, SelectorBothAsyncProto {
78-
func hello() async -> Bool { true }
79-
}
80-
class SelectorBothAsync2: NSObject, SelectorBothAsyncProto {
81-
func hello(completion: @escaping (Bool) -> Void) { completion(true) }
82-
}
83-
84-
// but not without declaring the async alternative.
85-
@objc protocol BadSelectorBothAsyncProto {
86-
@objc(helloWithCompletion:)
87-
func hello() async -> Bool // expected-note {{method 'hello()' declared here}}
88-
89-
@objc(helloWithCompletion:)
90-
func hello(completion: @escaping (Bool) -> Void) // expected-warning {{method 'hello(completion:)' with Objective-C selector 'helloWithCompletion:' conflicts with method 'hello()' with the same Objective-C selector; this is an error in Swift 6}}
91-
}
92-
9366
// additional coverage for situation like C4, where the method names don't
9467
// clash on the ObjC side, but they do on Swift side, BUT their ObjC selectors
9568
// differ, so it's OK.

0 commit comments

Comments
 (0)