Nim icon indicating copy to clipboard operation
Nim copied to clipboard

multisync macro return type doesn't resolve tuples

Open lantos1618 opened this issue 2 years ago • 0 comments

(Consider writing a PR targetting devel branch after filing this, see contributing.html).

multisync macro does not resolve tuples and complex return values

Example

import asyncdispatch
type 
    Sync = object
    Async = object
    SyncRes = (Sync, string)
    AsyncRes = (Async, string)

# doesn't extract tuple from multisync 
proc multiSyncTuppleResponse(val: Sync | Async): Future[(Async, string) | (sync, string)] {.multisync.} =
# proc multiSyncTuppleResponse(val: Sync | Async): Future[SyncRes | AsyncRes] {.multisync.} =
    return (val, "hello")

proc main() {.async.} =
    var
        myAsync: Async
        res: string
    (myAsync, res) = await multiSyncTuppleResponse(myAsync)
    echo res
when isMainModule:
    waitFor main()


Current Output

please check whether the problem still exists in git head before posting, see rebuilding the compiler.

~/.choosenim/toolchains/nim-#devel/lib/pure/asyncmacro.nim(278, 45) Error: node lacks field: strVal```

Expected Output

hello

Possible Solution

extract tuples / complex types out of the return type Temporary solution

Type
    SyncRes = (Sync, string)
    AsyncRes = (Async, string)

Future[(Async, string) | (sync, string)] {.multisync.} = to Future[SyncRes | AsyncRes] {.multisync.} =

Other solution add mappings to https://github.com/nim-lang/Nim/blob/528b6d1c3f001944a7a7754c8884178e365e6871/lib/pure/asyncmacro.nim#L278

Additional Information

$ nim -v
Nim Compiler Version 1.7.1 [MacOSX: amd64]
Compiled at 2022-07-17
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 0d8bec695606a65c5916d0da7fcb0a976a4e1f7b
active boot switches: -d:release

lantos1618 avatar Jul 30 '22 10:07 lantos1618