Skip to content

Commit 59fbafa

Browse files
committed
add test coverage for defer in actor initializers
The expected diagnostics are emitted by DI, but I didn't see any regression test coverage. resolves rdar://83957881
1 parent b203f5b commit 59fbafa

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/Concurrency/actor_definite_init.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,28 @@ actor Ahmad {
425425
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
426426
}
427427
}
428+
429+
@available(SwiftStdlib 5.5, *)
430+
actor Rain {
431+
var x: Int = 0
432+
func f() {}
433+
434+
init() {
435+
defer { self.f() } // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
436+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
437+
438+
defer { _ = self.x } // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
439+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
440+
441+
defer { Task { await self.f() } } // expected-warning {{this use of actor 'self' can only appear in an async initializer}}
442+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
443+
}
444+
445+
init() async {
446+
defer { self.f() }
447+
448+
defer { _ = self.x }
449+
450+
defer { Task { await self.f() } }
451+
}
452+
}

test/Concurrency/actor_definite_init_swift6.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,28 @@ actor Ahmad {
423423
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
424424
}
425425
}
426+
427+
@available(SwiftStdlib 5.5, *)
428+
actor Rain {
429+
var x: Int = 0
430+
func f() {}
431+
432+
init() {
433+
defer { self.f() } // expected-error {{this use of actor 'self' can only appear in an async initializer}}
434+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
435+
436+
defer { _ = self.x } // expected-error {{this use of actor 'self' can only appear in an async initializer}}
437+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
438+
439+
defer { Task { await self.f() } } // expected-error {{this use of actor 'self' can only appear in an async initializer}}
440+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
441+
}
442+
443+
init() async {
444+
defer { self.f() }
445+
446+
defer { _ = self.x }
447+
448+
defer { Task { await self.f() } }
449+
}
450+
}

0 commit comments

Comments
 (0)