File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ // RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
2+
3+ // REQUIRES: executable_test
4+ // REQUIRES: concurrency
5+
6+ // REQUIRES: concurrency_runtime
7+ // UNSUPPORTED: back_deployment_runtime
8+
9+ enum Maybe < T: Sendable > : Sendable {
10+ case just( T )
11+ case nothing
12+ }
13+
14+ @available ( SwiftStdlib 5 . 5 , * )
15+ actor Printer {
16+ var numPrints : Int = 0
17+
18+ func callAsFunction< T> ( _ x: Maybe < T > ) async {
19+ switch x {
20+ case . nothing: genericPrinter ( " nothing " , counter: & numPrints)
21+ case . just( let t) : genericPrinter ( t, counter: & numPrints)
22+ }
23+ }
24+
25+ func callAsFunction( _ x: String ) {
26+ genericPrinter ( x, counter: & numPrints)
27+ }
28+
29+ func callAsFunction( _ x: Int ) async throws {
30+ genericPrinter ( x, counter: & numPrints)
31+ }
32+
33+ @MainActor func callAsFunction( writingTo count: inout Maybe < Int > ) async {
34+ count = . just( await numPrints)
35+ }
36+
37+ private func genericPrinter< T> ( _ x: T , counter: inout Int ) {
38+ print ( x)
39+ counter += 1
40+ }
41+ }
42+
43+ @available ( SwiftStdlib 5 . 5 , * )
44+ @main struct Main {
45+ static func main( ) async {
46+ let p = Printer ( )
47+ var maybe : Maybe < Int > = . nothing
48+
49+ await p ( maybe)
50+ await p ( " cat " )
51+ try ! await p ( 2 )
52+ await p ( " cat " )
53+
54+
55+ await p ( writingTo: & maybe)
56+ await p ( maybe)
57+ }
58+ }
59+
60+ // CHECK: nothing
61+ // CHECK: cat
62+ // CHECK: 2
63+ // CHECK: cat
64+ // CHECK: 4
65+
You can’t perform that action at this time.
0 commit comments