nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.64k stars 1.47k forks source link

`Error: VM problem: dest register is not set` with `const`-bound proc #24359

Closed tersec closed 1 month ago

tersec commented 1 month ago

Description

proc h(_: bool) = discard
const m = h
static: m(true)  # works
m(true)          # does not work

Nim Version

Nim Compiler Version 2.0.10 [Linux: amd64]
Compiled at 2024-10-25
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: e941ee15be775fe3c46db1bed9b4f41c7dfb1334
active boot switches: -d:release
Nim Compiler Version 2.0.11 [Linux: amd64]
Compiled at 2024-10-25
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 76d834c1821f77b9f73b581f16895a1d2d1add11
active boot switches: -d:release
Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-25
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release
Nim Compiler Version 2.2.1 [Linux: amd64]
Compiled at 2024-10-25
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 820e2bee9c14916f719815be0460fc09e8067531
active boot switches: -d:release

Current Output

w.nim(4, 2) Error: VM problem: dest register is not set

Expected Output

No VM problem (indeed, the VM problem only occurs in the non-static context, so it's definitely possible, because if the static context can run, the non-static context can at least compile)

Known Workarounds

No response

Additional Information

No response

metagn commented 1 month ago

Works:

proc h(_: bool): bool = discard
const m = h
static: echo m(true)
echo m(true)

So seems to be a problem with returning void

Also, the compiler is tries to fold all calls to const procs at compile time, maybe not correct