You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't check sendability of witnesses for @preconcurrency conformances
When a witness is part of a `@preconcurrency` conformance, suppress
Sendable checking for that witness because we assume that the caller is
correctly invoking this witness from within the right isolation
domain. This property is dynamically checked.
Fixes#74057.
// expected-note@-1 6 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
39
38
40
39
protocolTestSendability{
41
40
varx:NonSendable{get}
42
41
func test(_:NonSendable?)->[NonSendable]
43
42
}
44
43
45
-
// Make sure that preconcurrency conformances don't suppress Sendable diagnostics
44
+
// Make sure that preconcurrency conformances suppress Sendable diagnostics,
45
+
// because @preconcurrency assumes that the witness will always be called
46
+
// from within the same isolation domain (with a dynamic check).
46
47
@MainActor
47
48
structValue:@preconcurrencyTestSendability{
48
49
varx:NonSendable{NonSendable()}
49
-
// expected-warning@-1 {{non-sendable type 'NonSendable' in conformance of main actor-isolated property 'x' to protocol requirement cannot cross actor boundary}}
50
-
// expected-note@-2 2 {{property declared here}}
50
+
// expected-note@-1 2 {{property declared here}}
51
51
52
-
// expected-warning@+2 {{non-sendable type '[NonSendable]' returned by main actor-isolated instance method 'test' satisfying protocol requirement cannot cross actor boundary}}
53
-
// expected-warning@+1 {{non-sendable type 'NonSendable?' in parameter of the protocol requirement satisfied by main actor-isolated instance method 'test' cannot cross actor boundary}}
54
52
func test(_:NonSendable?)->[NonSendable]{
55
53
// expected-note@-1 2 {{calls to instance method 'test' from outside of its actor context are implicitly asynchronous}}
56
54
[]
57
55
}
58
56
}
59
57
58
+
// Make sure we don't spuriously say the @preconcurrency is unnecessary.
// Make sure that references to actor isolated witness is diagnosed
61
69
62
70
// expected-note@+1 2 {{add '@MainActor' to make global function 'test(value:)' part of global actor 'MainActor'}}
@@ -73,10 +81,7 @@ actor MyActor {
73
81
74
82
extensionMyActor:@preconcurrencyTestSendability{
75
83
varx:NonSendable{NonSendable()}
76
-
// expected-warning@-1 {{non-sendable type 'NonSendable' in conformance of actor-isolated property 'x' to protocol requirement cannot cross actor boundary}}
77
84
78
-
// expected-warning@+2 {{non-sendable type '[NonSendable]' returned by actor-isolated instance method 'test' satisfying protocol requirement cannot cross actor boundary}}
79
-
// expected-warning@+1 {{non-sendable type 'NonSendable?' in parameter of the protocol requirement satisfied by actor-isolated instance method 'test' cannot cross actor boundary}}
0 commit comments