fixes #24359; VM problem: dest register is not set with const-bound proc (#24364)

fixes #24359

follow up https://github.com/nim-lang/Nim/pull/11076

It should not try to evaluate the const proc if the proc doesn't have a
return value.

(cherry picked from commit 031ad957ba)
This commit is contained in:
ringabout
2024-10-27 02:49:07 +08:00
committed by narimiran
parent 52d94c1c86
commit 3c528c987c
2 changed files with 17 additions and 2 deletions

View File

@@ -1006,9 +1006,9 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
n.typ.flags.incl tfUnresolved
# optimization pass: not necessary for correctness of the semantic pass
if callee.kind == skConst or
if (callee.kind == skConst or
{sfNoSideEffect, sfCompileTime} * callee.flags != {} and
{sfForward, sfImportc} * callee.flags == {} and n.typ != nil:
{sfForward, sfImportc} * callee.flags == {}) and n.typ != nil:
if callee.kind != skConst and
sfCompileTime notin callee.flags and

View File

@@ -16,3 +16,18 @@ const G = proc ():int =
y()
echo G()
block: # bug #24359
block:
proc h(_: bool) = discard
const m = h
static: m(true) # works
m(true) # does not work
block:
block:
proc h(_: bool): int = result = 1
const m = h
static: doAssert m(true) == 1 # works
doAssert m(true) == 1 # does not work