mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-04 10:54:42 +00:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
19
tests/async/t20111.nim
Normal file
19
tests/async/t20111.nim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user