Skip to content

Commit fcba147

Browse files
authored
disable "dest register is set" for vm statements (#24797)
closes #24780 This proc `genStmt` is only called to run the VM in `vm.evalStmt`, otherwise it's not used in vmgen. Now it acts the same as `proc gen(PCtx, PNode)`, used by `discard` statements, which just calls `freeTemp` on the dest if it was set rather than erroring.
1 parent 482662d commit fcba147

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/vmgen.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,9 +2313,11 @@ proc genStmt*(c: PCtx; n: PNode): int =
23132313
result = c.code.len
23142314
var d: TDest = -1
23152315
c.gen(n, d)
2316-
c.gABC(n, opcEof)
23172316
if d >= 0:
2318-
globalError(c.config, n.info, "VM problem: dest register is set")
2317+
# for discardable calls etc, otherwise not valid
2318+
freeTemp(c, d)
2319+
#globalError(c.config, n.info, "VM problem: dest register is set")
2320+
c.gABC(n, opcEof)
23192321

23202322
proc genExpr*(c: PCtx; n: PNode, requiresValue = true): int =
23212323
c.removeLastEof

tests/test_nimscript.nims

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,10 @@ block: # cpDir, cpFile, dirExists, fileExists, mkDir, mvDir, mvFile, rmDir, rmF
136136
block:
137137
# check parseopt can get command line:
138138
discard initOptParser()
139+
140+
# issue #24780:
141+
142+
proc discardableCall(cmd: string): int {.discardable.} =
143+
result = 123
144+
145+
discardableCall "echo hi"

0 commit comments

Comments
 (0)