Skip to content

Commit fa413e8

Browse files
committed
[Concurrency] Don't perform actor isolation checking within #selector.
The code in #selector doesn't execute, so don't perform actor-isolation checking in there. It also happens to have subexpressions that don't really follow the rules for references to instance methods, so avoiding this checking eliminates both compiler crashes and been spurious errors. Fixes rdar://72945343.
1 parent 677424b commit fa413e8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,13 @@ namespace {
834834
}
835835
}
836836

837+
// The children of #selector expressions are not evaluation, so we do not
838+
// need to do isolation checking there. This is convenient because such
839+
// expressions tend to violate restrictions on the use of instance
840+
// methods.
841+
if (isa<ObjCSelectorExpr>(expr))
842+
return { false, expr };
843+
837844
return { true, expr };
838845
}
839846

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
// REQUIRES: concurrency
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
func g(_ selector: Selector) -> Int { }
8+
9+
actor class A {
10+
func selectors() {
11+
_ = #selector(type(of: self).f) // expected-error{{argument of '#selector' refers to instance method 'f()' that is not exposed to Objective-C}}
12+
_ = #selector(type(of: self).g) // expected-error{{argument of '#selector' refers to instance method 'g()' that is not exposed to Objective-C}}
13+
_ = #selector(type(of: self).h)
14+
}
15+
16+
func keypaths() {
17+
_ = #keyPath(A.x) // expected-error{{argument of '#keyPath' refers to non-'@objc' property 'x'}}
18+
_ = #keyPath(A.y) // expected-error{{argument of '#keyPath' refers to non-'@objc' property 'y'}}
19+
_ = #keyPath(A.z)
20+
}
21+
22+
var x: Int = 0 // expected-note{{add '@objc' to expose this property to Objective-C}}
23+
@objc var y: Int = 0 // expected-note{{add '@objc' to expose this property to Objective-C}}
24+
// expected-error@-1{{actor-isolated property 'y' cannot be @objc}}
25+
@objc @actorIndependent(unsafe) var z: Int = 0
26+
27+
func f() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}
28+
func g() { } // expected-note{{add '@objc' to expose this instance method to Objective-C}}
29+
@objc func h() async { }
30+
}
31+
32+
33+

0 commit comments

Comments
 (0)