Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks.toTask Doesn't Expect a Dot Expression #23635

Closed
Nmerryman opened this issue May 22, 2024 · 0 comments · Fixed by #23641
Closed

tasks.toTask Doesn't Expect a Dot Expression #23635

Nmerryman opened this issue May 22, 2024 · 0 comments · Fixed by #23641
Assignees

Comments

@Nmerryman
Copy link

Description

Trying to pass a proc stored in an object does not compile.
Here is a minimal code example that triggers the issue.

import std/tasks

type
    Store = object
        run: proc (a: int) {.nimcall, gcsafe.}

proc hello(a: int) = echo a

var store = Store()
store.run = hello

let b = toTask store.run(13)
b.invoke()

A workaround for this is to wrap the call in a proc that can avoid the dot notation.
For example, using the following lets it compile correctly.

proc runner(s: Store, n: int) =
    store.run(n)

let b = toTask runner(store, 13)

Nim Version

Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2024-02-10
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release

Current Output

C:\Users\_\.choosenim\toolchains\nim-#devel\lib\std\tasks.nim(124, 20) toTask
C:\Users\_\.choosenim\toolchains\nim-#devel\lib\std\effecttraits.nim(54, 3) isGcSafe
C:\Users\_\.choosenim\toolchains\nim-#devel\lib\core\macros.nim(689, 24) expectKind
d:\dump\Git\_\prep_tests\network_runner\code_format.nim(15, 21) Error: Expected a node of kind nnkSym, got nnkDotExpr

Expected Output

Compilation followed by "13"

Possible Solution

No response

Additional Information

No response

@ringabout ringabout self-assigned this May 23, 2024
Araq added a commit that referenced this issue May 27, 2024
fixes #23635

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
narimiran pushed a commit that referenced this issue Sep 13, 2024
fixes #23635

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit cc5ce72)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants