mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Allow #selector to reference async method in non-async code
Fixes rdar://153118331
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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:))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user