|
| 1 | +// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) |
| 2 | + |
| 3 | +// REQUIRES: executable_test |
| 4 | +// REQUIRES: concurrency |
| 5 | +// UNSUPPORTED: use_os_stdlib |
| 6 | +// UNSUPPORTED: back_deployment_runtime |
| 7 | + |
| 8 | +import _Concurrency |
| 9 | +import StdlibUnittest |
| 10 | + |
| 11 | +class P<T> { |
| 12 | + var t: T |
| 13 | + init(_ v: T) { |
| 14 | + t = v |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +class A {} |
| 19 | +class B {} |
| 20 | +class C {} |
| 21 | + |
| 22 | +enum E : Error { |
| 23 | + case err |
| 24 | +} |
| 25 | + |
| 26 | +protocol MP { } |
| 27 | + |
| 28 | +class M : MP { |
| 29 | + |
| 30 | + @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) |
| 31 | + func throwWithIndirectResult<T>(_ a: P<T>) async throws -> T { |
| 32 | + throw E.err |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +extension MP { |
| 37 | + @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) |
| 38 | + func l<A, B, C, D, E2, F> (_ a : P<A>, _ b: P<B>, _ c: P<C>, _ d : P<D>, _ e: P<E2>, _ f: P<F>) async throws -> (A, B, C, D, E2, F) { |
| 39 | + throw E.err |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +@main struct Main { |
| 44 | + static func main() async { |
| 45 | + var tests = TestSuite("Async Throw") |
| 46 | + |
| 47 | + if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) { |
| 48 | + tests.test("throwing of naturally direct but indirect reabstration") { |
| 49 | + let task2 = detach { |
| 50 | + let m = M() |
| 51 | + await verifyCancelled { |
| 52 | + try await m.l(P(A()), P(B()), P(C()), P(A()), P(B()), P(C())) |
| 53 | + } |
| 54 | + func verifyCancelled<T>(execute operation: () async throws -> T) async { |
| 55 | + do { |
| 56 | + let _ = try await operation() |
| 57 | + assertionFailure("operation() threw") |
| 58 | + } |
| 59 | + catch _ as E { |
| 60 | + // This is what we expect to happen |
| 61 | + } |
| 62 | + catch { |
| 63 | + assertionFailure("unknown error thrown") |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + _ = await task2.get() |
| 68 | + } |
| 69 | + tests.test("throwing with indirect result") { |
| 70 | + let task2 = detach { |
| 71 | + let m = M() |
| 72 | + do { |
| 73 | + let _ = try await m.throwWithIndirectResult(P(A())) |
| 74 | + assertionFailure("operation() threw") |
| 75 | + } |
| 76 | + catch _ as E { |
| 77 | + // This is what we expect to happen |
| 78 | + } |
| 79 | + catch { |
| 80 | + assertionFailure("unknown error thrown") |
| 81 | + } |
| 82 | + } |
| 83 | + _ = await task2.get() |
| 84 | + } |
| 85 | + } |
| 86 | + await runAllTestsAsync() |
| 87 | + } |
| 88 | +} |
0 commit comments