diff --git a/compiler/vm.nim b/compiler/vm.nim index f69b9281de..ae5fcb43ff 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -984,6 +984,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let rb = instr.regBx - wordExcess let cnst = c.constants.sons[rb] if fitsRegister(cnst.typ): + myreset(regs[ra]) putIntoReg(regs[ra], cnst) else: ensureKind(rkNode) diff --git a/tests/vm/tldconst.nim b/tests/vm/tldconst.nim new file mode 100644 index 0000000000..9eabb75259 --- /dev/null +++ b/tests/vm/tldconst.nim @@ -0,0 +1,14 @@ +# Passes if it compiles +# From issue #1946 + +type + Part = object + index: int ## array index of argument to be accessed + +proc foobar(): int = + var x: Part + if x.index < high(int): + discard + 0 + +const x = foobar() \ No newline at end of file