File tree Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -2930,8 +2930,10 @@ namespace {
29302930 auto *explicitClosure = dyn_cast_or_null<ClosureExpr>(closure);
29312931
29322932 bool preconcurrency = false ;
2933- if (explicitClosure) {
2934- preconcurrency = explicitClosure->isIsolatedByPreconcurrency ();
2933+ if (closure) {
2934+ preconcurrency =
2935+ getActorIsolationOfContext (closure, getClosureActorIsolation)
2936+ .preconcurrency ();
29352937 }
29362938
29372939 for (const auto &capture : localFunc.getCaptureInfo ().getCaptures ()) {
Original file line number Diff line number Diff line change 5050 }
5151 }
5252}
53+
54+ func use( _ closure: @autoclosure ( ) -> Any ) {
55+ }
56+
57+ do {
58+ class C {
59+ @preconcurrency static func f( _: @escaping @Sendable ( ) -> Void ) { }
60+ }
61+
62+ class SelfCapture { // expected-note 5 {{class 'SelfCapture' does not conform to the 'Sendable' protocol}}
63+ func fooDirect( ) {
64+ C . f {
65+ use ( self )
66+ // expected-warning@-1 {{capture of 'self' with non-sendable type 'SelfCapture' in a '@Sendable' closure}}
67+ // expected-warning@-2 {{implicit capture of 'self' requires that 'SelfCapture' conforms to 'Sendable'}}
68+ }
69+ }
70+
71+ func fooThroughClosure( ) {
72+ C . f {
73+ { use ( self ) } ( )
74+ // expected-warning@-1 {{capture of 'self' with non-sendable type 'SelfCapture' in a '@Sendable' closure}}
75+ // expected-warning@-2 {{capture of 'self' with non-sendable type 'SelfCapture' in an isolated closure}}
76+ // expected-warning@-3 {{implicit capture of 'self' requires that 'SelfCapture' conforms to 'Sendable'}}
77+ }
78+ }
79+ }
80+ }
Original file line number Diff line number Diff line change @@ -86,6 +86,10 @@ void doSomethingConcurrently(__attribute__((noescape)) void SWIFT_SENDABLE (^blo
8686- ( void) testWithComplet ion: ( void ( ^) ( void) ) completion;
8787@end
8888
89+ @interface TestSelfCapture : NSObject
90+ + ( void) do WithComplet ion : ( void ( ^) ( void ) ) complet ion;
91+ @end
92+
8993#pragma clang assume_nonnull end
9094
9195//--- main.swift
@@ -219,3 +223,25 @@ extension TestDR {
219223 @_dynamicReplacement ( for: test ( completion: ) )
220224 func __replaceObjCFunc( _: @escaping ( ) -> Void ) { } // Ok
221225}
226+
227+ class SelfCapture { // expected-note 5 {{class 'SelfCapture' does not conform to the 'Sendable' protocol}}
228+ static func use( _ closure: @autoclosure ( ) -> Any ) {
229+ }
230+
231+ func testDirect( ) {
232+ TestSelfCapture . do {
233+ Self . use ( self )
234+ // expected-warning@-1 {{capture of 'self' with non-sendable type 'SelfCapture' in a '@Sendable' closure}}
235+ // expected-warning@-2 {{implicit capture of 'self' requires that 'SelfCapture' conforms to 'Sendable'}}
236+ }
237+ }
238+
239+ func testThroughClosure( ) {
240+ TestSelfCapture . do {
241+ let _ = { Self . use ( self ) } ( )
242+ // expected-warning@-1 {{capture of 'self' with non-sendable type 'SelfCapture' in a '@Sendable' closure}}
243+ // expected-warning@-2 {{capture of 'self' with non-sendable type 'SelfCapture' in an isolated closure}}
244+ // expected-warning@-3 {{implicit capture of 'self' requires that 'SelfCapture' conforms to 'Sendable'}}
245+ }
246+ }
247+ }
You can’t perform that action at this time.
0 commit comments