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
[send-non-sendable] Ensure that we properly warn if a field of a final actor is transferred.
Previously, we were not recognizing that a ref_element_addr from an actor object
is equivalent to the actor object and we shouldn't allow for it to be consumed.
rdar://115132118
varc=NonSendableKlass() // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
31
69
let _ ={print(c)}
32
70
}
71
+
72
+
// In this test, closure is not promoted into its box form. As a result, we
73
+
// treat assignments into contents as a merge operation rather than an assign.
74
+
func closureInOut(_ a:Actor)async{
75
+
varcontents=NonSendableKlass()
76
+
letns0=NonSendableKlass()
77
+
letns1=NonSendableKlass()
78
+
79
+
contents = ns0
80
+
contents = ns1
81
+
82
+
varclosure={}
83
+
closure ={useInOut(&contents)}
84
+
85
+
await a.useKlass(ns0) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
86
+
await a.useKlass(ns1) // expected-note {{access here could race}}
87
+
88
+
closure() // expected-note {{access here could race}}
89
+
}
90
+
91
+
func closureInOut2(_ a:Actor)async{
92
+
varcontents=NonSendableKlass()
93
+
letns0=NonSendableKlass()
94
+
letns1=NonSendableKlass()
95
+
96
+
contents = ns0
97
+
contents = ns1
98
+
99
+
varclosure={}
100
+
101
+
await a.useKlass(ns0) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
102
+
103
+
closure ={useInOut(&contents)} // expected-note {{access here could race}}
104
+
105
+
await a.useKlass(ns1) // expected-note {{access here could race}}
106
+
107
+
closure()
108
+
}
109
+
110
+
func closureNonInOut(_ a:Actor)async{
111
+
varcontents=NonSendableKlass()
112
+
letns0=NonSendableKlass()
113
+
letns1=NonSendableKlass()
114
+
115
+
contents = ns0
116
+
contents = ns1
117
+
118
+
varclosure={}
119
+
120
+
await a.useKlass(ns0)
121
+
122
+
closure ={useValue(contents)}
123
+
124
+
await a.useKlass(ns1) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
125
+
126
+
closure() // expected-note {{access here could race}}
0 commit comments