Skip to content

Commit e206faa

Browse files
authored
Merge pull request #38314 from kavon/5.5-only-warn-actor-inits
[5.5] quick downgrade of actor-init restrictions to warning
2 parents b22c289 + f19aef4 commit e206faa

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ ERROR(self_closure_use_uninit,none,
169169
"'self' captured by a closure before all members were initialized", ())
170170

171171
/// false == sync; true == global-actor isolated
172-
ERROR(self_use_actor_init,none,
172+
WARNING(self_use_actor_init,none,
173173
"this use of actor 'self' %select{can only|cannot}0 appear in "
174174
"%select{an async|a global-actor isolated}0 initializer",
175175
(bool))
176-
ERROR(self_disallowed_actor_init,none,
176+
WARNING(self_disallowed_actor_init,none,
177177
"actor 'self' %select{can only|cannot}0 %1 from "
178178
"%select{an async|a global-actor isolated}0 initializer",
179179
(bool, StringRef))

test/Concurrency/actor_definite_init.swift

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ actor Convenient {
4848
init(throwyDesignated val: Int) throws {
4949
guard val > 0 else { throw BogusError.blah }
5050
self.x = 10
51-
say(msg: "hello?") // expected-error {{this use of actor 'self' can only appear in an async initializer}}
51+
say(msg: "hello?") // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
5252
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
5353

54-
Task { self } // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
54+
Task { self } // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
5555
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
5656
}
5757

@@ -109,32 +109,32 @@ actor MyActor {
109109
_ = self.x
110110
self.y = self.x
111111

112-
Task { self } // expected-error{{actor 'self' can only be captured by a closure from an async initializer}}
112+
Task { self } // expected-warning{{actor 'self' can only be captured by a closure from an async initializer}}
113113
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
114114

115-
self.helloWorld() // expected-error{{this use of actor 'self' can only appear in an async initializer}}
115+
self.helloWorld() // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
116116
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
117117

118-
callMethod(self) // expected-error{{this use of actor 'self' can only appear in an async initializer}}
118+
callMethod(self) // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
119119
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
120120

121-
passInout(&self.x) // expected-error{{actor 'self' can only be passed 'inout' from an async initializer}}
121+
passInout(&self.x) // expected-warning{{actor 'self' can only be passed 'inout' from an async initializer}}
122122

123123
self.x = self.y
124124
self.x = randomInt()
125125
(_, _) = (self.x, self.y)
126126
_ = self.x == 0
127127

128-
self.hax = self // expected-error{{this use of actor 'self' can only appear in an async initializer}}
128+
self.hax = self // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
129129
_ = self.hax
130130

131-
_ = computedProp // expected-error{{this use of actor 'self' can only appear in an async initializer}}
131+
_ = computedProp // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
132132
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
133133

134-
computedProp = 1 // expected-error{{this use of actor 'self' can only appear in an async initializer}}
134+
computedProp = 1 // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
135135
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
136136

137-
Task { // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
137+
Task { // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
138138
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
139139
_ = await self.hax
140140
await self.helloWorld()
@@ -146,29 +146,29 @@ actor MyActor {
146146
guard c else { return nil }
147147
self.y = self.x
148148

149-
Task { self } // expected-error{{actor 'self' can only be captured by a closure from an async initializer}}
149+
Task { self } // expected-warning{{actor 'self' can only be captured by a closure from an async initializer}}
150150
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
151151

152-
self.helloWorld() // expected-error{{this use of actor 'self' can only appear in an async initializer}}
152+
self.helloWorld() // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
153153
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
154154

155-
callMethod(self) // expected-error{{this use of actor 'self' can only appear in an async initializer}}
155+
callMethod(self) // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
156156
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
157157

158-
passInout(&self.x) // expected-error{{actor 'self' can only be passed 'inout' from an async initializer}}
158+
passInout(&self.x) // expected-warning{{actor 'self' can only be passed 'inout' from an async initializer}}
159159

160160
self.x = self.y
161161

162-
self.hax = self // expected-error{{this use of actor 'self' can only appear in an async initializer}}
162+
self.hax = self // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
163163
_ = self.hax
164164

165-
_ = computedProp // expected-error{{this use of actor 'self' can only appear in an async initializer}}
165+
_ = computedProp // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
166166
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
167167

168-
computedProp = 1 // expected-error{{this use of actor 'self' can only appear in an async initializer}}
168+
computedProp = 1 // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
169169
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
170170

171-
Task { // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
171+
Task { // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
172172
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
173173
_ = await self.hax
174174
await self.helloWorld()
@@ -180,29 +180,29 @@ actor MyActor {
180180
guard c else { return nil }
181181
self.y = self.x
182182

183-
Task { self } // expected-error{{actor 'self' can only be captured by a closure from an async initializer}}
183+
Task { self } // expected-warning{{actor 'self' can only be captured by a closure from an async initializer}}
184184
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
185185

186-
self.helloWorld() // expected-error{{this use of actor 'self' can only appear in an async initializer}}
186+
self.helloWorld() // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
187187
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
188188

189-
callMethod(self) // expected-error{{this use of actor 'self' can only appear in an async initializer}}
189+
callMethod(self) // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
190190
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
191191

192-
passInout(&self.x) // expected-error{{actor 'self' can only be passed 'inout' from an async initializer}}
192+
passInout(&self.x) // expected-warning{{actor 'self' can only be passed 'inout' from an async initializer}}
193193

194194
self.x = self.y
195195

196-
self.hax = self // expected-error{{this use of actor 'self' can only appear in an async initializer}}
196+
self.hax = self // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
197197
_ = self.hax
198198

199-
_ = computedProp // expected-error{{this use of actor 'self' can only appear in an async initializer}}
199+
_ = computedProp // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
200200
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
201201

202-
computedProp = 1 // expected-error{{this use of actor 'self' can only appear in an async initializer}}
202+
computedProp = 1 // expected-warning{{this use of actor 'self' can only appear in an async initializer}}
203203
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
204204

205-
Task { // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
205+
Task { // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
206206
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
207207
_ = await self.hax
208208
await self.helloWorld()
@@ -214,29 +214,29 @@ actor MyActor {
214214
self.x = 0
215215
self.y = self.x
216216

217-
Task { self } // expected-error{{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
217+
Task { self } // expected-warning{{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
218218
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
219219

220-
self.helloWorld() // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
220+
self.helloWorld() // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
221221
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
222222

223-
callMethod(self) // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
223+
callMethod(self) // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
224224
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
225225

226-
passInout(&self.x) // expected-error{{actor 'self' cannot be passed 'inout' from a global-actor isolated initializer}}
226+
passInout(&self.x) // expected-warning{{actor 'self' cannot be passed 'inout' from a global-actor isolated initializer}}
227227

228228
self.x = self.y
229229

230-
self.hax = self // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
230+
self.hax = self // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
231231
_ = self.hax
232232

233-
_ = computedProp // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
233+
_ = computedProp // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
234234
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
235235

236-
computedProp = 1 // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
236+
computedProp = 1 // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
237237
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
238238

239-
Task { // expected-error {{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
239+
Task { // expected-warning {{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
240240
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
241241
_ = await self.hax
242242
await self.helloWorld()
@@ -272,29 +272,29 @@ actor MyActor {
272272
self.x = 0
273273
self.y = self.x
274274

275-
Task { self } // expected-error{{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
275+
Task { self } // expected-warning{{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
276276
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
277277

278-
self.helloWorld() // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
278+
self.helloWorld() // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
279279
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
280280

281-
callMethod(self) // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
281+
callMethod(self) // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
282282
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
283283

284-
passInout(&self.x) // expected-error{{actor 'self' cannot be passed 'inout' from a global-actor isolated initializer}}
284+
passInout(&self.x) // expected-warning{{actor 'self' cannot be passed 'inout' from a global-actor isolated initializer}}
285285

286286
self.x = self.y
287287

288-
self.hax = self // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
288+
self.hax = self // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
289289
_ = self.hax
290290

291-
_ = computedProp // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
291+
_ = computedProp // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
292292
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
293293

294-
computedProp = 1 // expected-error{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
294+
computedProp = 1 // expected-warning{{this use of actor 'self' cannot appear in a global-actor isolated initializer}}
295295
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
296296

297-
Task { // expected-error {{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
297+
Task { // expected-warning {{actor 'self' cannot be captured by a closure from a global-actor isolated initializer}}
298298
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
299299
_ = await self.hax
300300
await self.helloWorld()
@@ -310,7 +310,7 @@ actor X {
310310

311311
init(v1 start: Int) {
312312
self.counter = start
313-
Task { await self.setCounter(start + 1) } // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
313+
Task { await self.setCounter(start + 1) } // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
314314
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
315315

316316
if self.counter != start {
@@ -338,7 +338,7 @@ actor EscapeArtist {
338338
init(attempt1: Bool) {
339339
self.x = 0
340340

341-
globalVar = self // expected-error {{this use of actor 'self' can only appear in an async initializer}}
341+
globalVar = self // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
342342
Task { await globalVar!.isolatedMethod() }
343343

344344
if self.x == 0 {
@@ -349,7 +349,7 @@ actor EscapeArtist {
349349
init(attempt2: Bool) {
350350
self.x = 0
351351

352-
let wrapped: EscapeArtist? = .some(self) // expected-error {{this use of actor 'self' can only appear in an async initializer}}
352+
let wrapped: EscapeArtist? = .some(self) // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
353353
let selfUnchained = wrapped!
354354

355355
Task { await selfUnchained.isolatedMethod() }
@@ -362,7 +362,7 @@ actor EscapeArtist {
362362
self.x = 0
363363

364364
// expected-warning@+2 {{variable 'unchainedSelf' was never mutated; consider changing to 'let' constant}}
365-
// expected-error@+1 {{this use of actor 'self' can only appear in an async initializer}}
365+
// expected-warning@+1 {{this use of actor 'self' can only appear in an async initializer}}
366366
var unchainedSelf = self
367367

368368
unchainedSelf.nonisolated()
@@ -373,17 +373,17 @@ actor EscapeArtist {
373373

374374
let unchainedSelf = self
375375

376-
unchainedSelf.nonisolated() // expected-error {{this use of actor 'self' can only appear in an async initializer}}
376+
unchainedSelf.nonisolated() // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
377377
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
378378

379-
let _ = { unchainedSelf.nonisolated() } // expected-error {{actor 'self' can only be captured by a closure from an async initializer}}
379+
let _ = { unchainedSelf.nonisolated() } // expected-warning {{actor 'self' can only be captured by a closure from an async initializer}}
380380
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
381381
}
382382

383383
init(attempt5: Bool) {
384384
self.x = 0
385385

386-
let box = CardboardBox(item: self) // expected-error {{this use of actor 'self' can only appear in an async initializer}}
386+
let box = CardboardBox(item: self) // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
387387
box.item.nonisolated()
388388
}
389389

@@ -392,7 +392,7 @@ actor EscapeArtist {
392392
func fn() {
393393
self.nonisolated()
394394
}
395-
fn() // expected-error {{this use of actor 'self' can only appear in an async initializer}}
395+
fn() // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
396396
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
397397
}
398398

0 commit comments

Comments
 (0)