Skip to content

Commit c34f81e

Browse files
committed
Allow #selector to reference async method in non-async code
Fixes rdar://153118331
1 parent 96297e6 commit c34f81e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,13 @@ class Context {
30613061
return copy;
30623062
}
30633063

3064+
/// Form a subcontext that handles all async calls.
3065+
Context withHandlesAsync() const {
3066+
Context copy = *this;
3067+
copy.HandlesAsync = true;
3068+
return copy;
3069+
}
3070+
30643071
Kind getKind() const { return TheKind; }
30653072

30663073
DeclContext *getDeclContext() const { return DC; }
@@ -4068,7 +4075,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
40684075

40694076
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
40704077
// Walk the operand.
4071-
ContextScope scope(*this, std::nullopt);
4078+
ContextScope scope(*this, CurContext.withHandlesAsync());
40724079
scope.enterNonExecuting();
40734080

40744081
E->getSubExpr()->walk(*this);

test/expr/primary/selector/selector.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,13 @@ func test() -> Selector {
180180
func testWithThrowing(obj: AnyObject) {
181181
_ = #selector(HasThrows.doSomething(to:))
182182
}
183+
184+
@available(SwiftStdlib 5.1, *)
185+
@objc protocol HasAsync {
186+
@objc optional func doSomething(to object: AnyObject) async -> Void
187+
}
188+
189+
@available(SwiftStdlib 5.1, *)
190+
func testWithAsync(obj: AnyObject) {
191+
_ = #selector(HasAsync.doSomething(to:))
192+
}

0 commit comments

Comments
 (0)