Skip to content

Poor error message for spawn when a procedure (without calling it) is passed #7535

@k0pernicus

Description

@k0pernicus

Nim version: 0.18.0 [MacOSX: amd64]

I experimented the behaviour of spawn and parallel for a project, and I got an issue passing an anonymous procedure to spawn.

The following code demonstrates the expected behaviour:

proc my_proc(x: uint32) =
    echo x
proc print_parallel_ok(r: uint32) =
    for x in 0..r:
        spawn my_proc x

The compiler compiles the code, and running it is ok.

Otherwise, the following demonstrates the error:

proc print_parallel_nok(r: uint32) =
    for x in 0..r:
        spawn (proc (x: uint32) = echo x)

Here, instead of using a named procedure, I passed an anonymous procedure to spawn.

The error, passing an anonymous procedure to spawn is: expression 'spawn proc (x: uint32) = echo [x], nimCreateFlowVar' is of type 'FlowVar[proc (x: uint32){.gcsafe, locks: 0.}]' and has to be discarded.
Also, if I add a discard, I get an internal compiler error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions