From c7493bbdd0a9b8d63d6851971f2294923cf2e3a7 Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Mon, 12 Dec 2022 00:44:41 +1100 Subject: [PATCH] `multisync` now allows tuples in return type (#21074) * Add test case * Use .toStrLit() on param node first This means that more complex types are fully rendered --- lib/pure/asyncmacro.nim | 4 ++-- tests/async/t20111.nim | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/async/t20111.nim diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index fa5d981a7e..c4f6fd80ea 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -286,8 +286,8 @@ macro async*(prc: untyped): untyped = proc splitParamType(paramType: NimNode, async: bool): NimNode = result = paramType if paramType.kind == nnkInfix and paramType[0].strVal in ["|", "or"]: - let firstAsync = "async" in paramType[1].strVal.normalize - let secondAsync = "async" in paramType[2].strVal.normalize + let firstAsync = "async" in paramType[1].toStrLit().strVal.normalize + let secondAsync = "async" in paramType[2].toStrLit().strVal.normalize if firstAsync: result = paramType[if async: 1 else: 2] diff --git a/tests/async/t20111.nim b/tests/async/t20111.nim new file mode 100644 index 0000000000..0aaa7d8864 --- /dev/null +++ b/tests/async/t20111.nim @@ -0,0 +1,19 @@ +discard """ + action: "run" +""" +import asyncdispatch +type + Sync = object + Async = object + SyncRes = (Sync, string) + AsyncRes = (Async, string) + +proc foo(val: Sync | Async): Future[(Async, string) | (Sync, string)] {.multisync.} = + return (val, "hello") + +let + myAsync = Async() + mySync = Sync() + +doAssert typeof(waitFor foo(myAsync)) is AsyncRes +doAssert typeof(foo(mySync)) is SyncRes