Allow #selector to reference async method in non-async code

Fixes rdar://153118331
This commit is contained in:
Doug Gregor
2025-06-23 12:41:18 -07:00
parent 96297e61ee
commit c34f81e110
2 changed files with 18 additions and 1 deletions

View File

@@ -3061,6 +3061,13 @@ public:
return copy;
}
/// Form a subcontext that handles all async calls.
Context withHandlesAsync() const {
Context copy = *this;
copy.HandlesAsync = true;
return copy;
}
Kind getKind() const { return TheKind; }
DeclContext *getDeclContext() const { return DC; }
@@ -4068,7 +4075,7 @@ private:
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
// Walk the operand.
ContextScope scope(*this, std::nullopt);
ContextScope scope(*this, CurContext.withHandlesAsync());
scope.enterNonExecuting();
E->getSubExpr()->walk(*this);

View File

@@ -180,3 +180,13 @@ func test() -> Selector {
func testWithThrowing(obj: AnyObject) {
_ = #selector(HasThrows.doSomething(to:))
}
@available(SwiftStdlib 5.1, *)
@objc protocol HasAsync {
@objc optional func doSomething(to object: AnyObject) async -> Void
}
@available(SwiftStdlib 5.1, *)
func testWithAsync(obj: AnyObject) {
_ = #selector(HasAsync.doSomething(to:))
}