|
| 1 | +// RUN: %target-typecheck-verify-swift -target %target-swift-5.1-abi-triple |
| 2 | + |
| 3 | +// REQUIRES: concurrency |
| 4 | + |
| 5 | +@execution(concurrent) |
| 6 | +func concurrentTest() async { |
| 7 | +} |
| 8 | + |
| 9 | +@execution(caller) |
| 10 | +func callerTest() async { |
| 11 | +} |
| 12 | + |
| 13 | +@MainActor |
| 14 | +func actorIsolated() async {} |
| 15 | + |
| 16 | +let _: @execution(caller) () async -> Void = concurrentTest // Ok |
| 17 | +let _: @execution(concurrent) () async -> Void = callerTest // Ok |
| 18 | + |
| 19 | +let _: @MainActor () async -> Void = concurrentTest // Ok |
| 20 | +let _: @MainActor () async -> Void = callerTest // Ok |
| 21 | + |
| 22 | +let _: @isolated(any) () async -> Void = concurrentTest // Ok |
| 23 | +let _: @isolated(any) () async -> Void = callerTest |
| 24 | +// expected-error@-1 {{cannot convert value of type '@execution(caller) () async -> ()' to specified type '@isolated(any) () async -> Void'}} |
| 25 | + |
| 26 | +let _: @execution(caller) () async -> Void = actorIsolated // Ok |
| 27 | +let _: @execution(concurrent) () async -> Void = actorIsolated // Ok |
| 28 | + |
| 29 | +func testIsolationErasure(fn: @escaping @isolated(any) () async -> Void) { |
| 30 | + let _: @execution(concurrent) () async -> Void = fn // Ok |
| 31 | + let _: @execution(caller) () async -> Void = fn // Ok |
| 32 | +} |
| 33 | + |
| 34 | +func testUpcast(arr: [@execution(caller) () async -> Void]) { |
| 35 | + let _: [() async -> Void] = arr // Ok - collection upcast |
| 36 | + let _: [String: () async -> Void] = ["": arr] |
| 37 | + // expected-error@-1 {{cannot convert value of type '[@execution(caller) () async -> Void]' to expected dictionary value type '() async -> Void'}} |
| 38 | +} |
| 39 | + |
| 40 | +// Isolated parameter |
| 41 | +func testParameterIsolation(fn: @escaping (isolated (any Actor)?) async -> Void) { |
| 42 | + let _: @execution(caller) () async -> Void = fn |
| 43 | + // expected-error@-1 {{cannot convert value of type '(isolated (any Actor)?) async -> Void' to specified type '@execution(caller) () async -> Void'}} |
| 44 | + let _: @execution(concurrent) () async -> Void = fn |
| 45 | + // expected-error@-1 {{cannot convert value of type '(isolated (any Actor)?) async -> Void' to specified type '() async -> Void'}} |
| 46 | +} |
| 47 | + |
| 48 | +// Non-conversion situations |
| 49 | +do { |
| 50 | + struct S<T> { |
| 51 | + } |
| 52 | + func test<T>(_: S<T>, _: T.Type) {} |
| 53 | + |
| 54 | + test(S<() async -> Void>(), type(of: callerTest)) |
| 55 | + // expected-error@-1 {{cannot convert value of type '(@execution(caller) () async -> ()).Type' to expected argument type '(() async -> Void).Type'}} |
| 56 | + |
| 57 | + test(S<@execution(caller) () async -> Void>(), type(of: concurrentTest)) |
| 58 | + // expected-error@-1 {{cannot convert value of type '(() async -> ()).Type' to expected argument type '(@execution(caller) () async -> Void).Type'}} |
| 59 | + |
| 60 | + test(S<@MainActor () async -> Void>(), type(of: callerTest)) |
| 61 | + // expected-error@-1 {{cannot convert value of type '(@execution(caller) () async -> ()).Type' to expected argument type '(@MainActor () async -> Void).Type'}} |
| 62 | + |
| 63 | + test(S<@MainActor () async -> Void>(), type(of: concurrentTest)) |
| 64 | + // expected-error@-1 {{cannot convert value of type '(() async -> ()).Type' to expected argument type '(@MainActor () async -> Void).Type'}} |
| 65 | + |
| 66 | + test(S<(isolated (any Actor)?) async -> Void>(), type(of: callerTest)) |
| 67 | + // expected-error@-1 {{cannot convert value of type '(@execution(caller) () async -> ()).Type' to expected argument type '((isolated (any Actor)?) async -> Void).Type'}} |
| 68 | + |
| 69 | + test(S<(isolated (any Actor)?) async -> Void>(), type(of: concurrentTest)) |
| 70 | + // expected-error@-1 {{cannot convert value of type '(() async -> ()).Type' to expected argument type '((isolated (any Actor)?) async -> Void).Type'}} |
| 71 | + |
| 72 | + test(S<@isolated(any) () async -> Void>(), type(of: concurrentTest)) |
| 73 | + // expected-error@-1 {{cannot convert value of type '(() async -> ()).Type' to expected argument type '(@isolated(any) () async -> Void).Type'}} |
| 74 | + test(S<@isolated(any) () async -> Void>(), type(of: callerTest)) |
| 75 | + // expected-error@-1 {{cannot convert value of type '(@execution(caller) () async -> ()).Type' to expected argument type '(@isolated(any) () async -> Void).Type'}} |
| 76 | +} |
| 77 | + |
0 commit comments