Skip to content

Commit 031ad95

Browse files
authored
fixes #24359; VM problem: dest register is not set with const-bound proc (#24364)
fixes #24359 follow up #11076 It should not try to evaluate the const proc if the proc doesn't have a return value.
1 parent 506c8a5 commit 031ad95

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

compiler/semexprs.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,9 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
10061006
n.typ.flags.incl tfUnresolved
10071007

10081008
# optimization pass: not necessary for correctness of the semantic pass
1009-
if callee.kind == skConst or
1009+
if (callee.kind == skConst or
10101010
{sfNoSideEffect, sfCompileTime} * callee.flags != {} and
1011-
{sfForward, sfImportc} * callee.flags == {} and n.typ != nil:
1011+
{sfForward, sfImportc} * callee.flags == {}) and n.typ != nil:
10121012

10131013
if callee.kind != skConst and
10141014
sfCompileTime notin callee.flags and

tests/vm/tconstprocassignments.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ const G = proc ():int =
1616
y()
1717

1818
echo G()
19+
20+
21+
block: # bug #24359
22+
block:
23+
proc h(_: bool) = discard
24+
const m = h
25+
static: m(true) # works
26+
m(true) # does not work
27+
28+
block:
29+
block:
30+
proc h(_: bool): int = result = 1
31+
const m = h
32+
static: doAssert m(true) == 1 # works
33+
doAssert m(true) == 1 # does not work

0 commit comments

Comments
 (0)