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
[Sema] Suppress actor isolation checking for @preconcurrency conformances
Suppress warnings/errors when actor isolated synchroneous witness
is matched against `@preconcurrency` conformance requirement.
Witness thunk assumes isolation of the witness but instead of a
hop to its executor it would emit a runtime check to make sure
that its always called from the expected context.
extensionTestPreconcurrencyAttr:@preconcurrencyQ{ // Ok
34
32
}
33
+
34
+
classNonSendable{}
35
+
// expected-note@-1 6 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
36
+
37
+
protocolTestSendability{
38
+
varx:NonSendable{get}
39
+
func test(_:NonSendable?)->[NonSendable]
40
+
}
41
+
42
+
// Make sure that preconcurrency conformances don't suppress Sendable diagnostics
43
+
@MainActor
44
+
structValue:@preconcurrencyTestSendability{
45
+
varx:NonSendable{NonSendable()}
46
+
// expected-warning@-1 {{non-sendable type 'NonSendable' in conformance of main actor-isolated property 'x' to protocol requirement cannot cross actor boundary}}
47
+
// expected-note@-2 2 {{property declared here}}
48
+
49
+
// expected-warning@+2 {{non-sendable type '[NonSendable]' returned by main actor-isolated instance method 'test' satisfying protocol requirement cannot cross actor boundary}}
50
+
// 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}}
51
+
func test(_:NonSendable?)->[NonSendable]{
52
+
// expected-note@-1 2 {{calls to instance method 'test' from outside of its actor context are implicitly asynchronous}}
53
+
[]
54
+
}
55
+
}
56
+
57
+
// Make sure that references to actor isolated witness is diagnosed
58
+
59
+
// expected-note@+1 2 {{add '@MainActor' to make global function 'test(value:)' part of global actor 'MainActor'}}
60
+
func test(value:Value){
61
+
_ = value.x
62
+
// expected-error@-1 {{main actor-isolated property 'x' can not be referenced from a non-isolated context}}
63
+
_ = value.test(nil)
64
+
// expected-error@-1 {{call to main actor-isolated instance method 'test' in a synchronous nonisolated context}}
65
+
}
66
+
67
+
actorMyActor{
68
+
varvalue:Value?=nil
69
+
}
70
+
71
+
extensionMyActor:@preconcurrencyTestSendability{
72
+
varx:NonSendable{NonSendable()}
73
+
// expected-warning@-1 {{non-sendable type 'NonSendable' in conformance of actor-isolated property 'x' to protocol requirement cannot cross actor boundary}}
74
+
75
+
// expected-warning@+2 {{non-sendable type '[NonSendable]' returned by actor-isolated instance method 'test' satisfying protocol requirement cannot cross actor boundary}}
76
+
// expected-warning@+1 {{non-sendable type 'NonSendable?' in parameter of the protocol requirement satisfied by actor-isolated instance method 'test' cannot cross actor boundary}}
77
+
func test(_:NonSendable?)->[NonSendable]{
78
+
[]
79
+
}
80
+
81
+
func test_ref_diagnostics(){
82
+
_ = value?.x
83
+
// expected-error@-1 {{main actor-isolated property 'x' can not be referenced on a non-isolated actor instance}}
84
+
_ = value?.test(nil)
85
+
// expected-error@-1 {{call to main actor-isolated instance method 'test' in a synchronous actor-isolated context}}
86
+
}
87
+
}
88
+
89
+
protocolInitializable{
90
+
init()
91
+
}
92
+
93
+
finalclassK:@preconcurrencyInitializable{
94
+
init(){} // Ok
95
+
}
96
+
97
+
protocolWithAssoc{
98
+
associatedtypeT
99
+
func test()->T
100
+
}
101
+
102
+
structTestConditional<T>{}
103
+
104
+
extensionTestConditional:@preconcurrencyWithAssocwhere T ==Int{
0 commit comments