Skip to content

Commit

Permalink
multisync now allows tuples in return type (#21074)
Browse files Browse the repository at this point in the history
* Add test case

* Use .toStrLit() on param node first

This means that more complex types are fully rendered
  • Loading branch information
ire4ever1190 authored Dec 11, 2022
1 parent 1585bfe commit c7493bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pure/asyncmacro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 19 additions & 0 deletions tests/async/t20111.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c7493bb

Please sign in to comment.