From f25c47db1ae7659785ef59964e353304dc5b01ee Mon Sep 17 00:00:00 2001 From: Audun Wilhelmsen Date: Fri, 16 Jan 2015 22:31:43 +0100 Subject: [PATCH 1/2] Add test for issue #1946 --- tests/vm/tldconst.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/vm/tldconst.nim diff --git a/tests/vm/tldconst.nim b/tests/vm/tldconst.nim new file mode 100644 index 000000000..9eabb7525 --- /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 From ca257efc84d6612665123349710f844d1d51be99 Mon Sep 17 00:00:00 2001 From: Audun Wilhelmsen Date: Fri, 16 Jan 2015 22:32:00 +0100 Subject: [PATCH 2/2] Proposed fix for issue #1946 --- compiler/vm.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/vm.nim b/compiler/vm.nim index f69b9281d..ae5fcb43f 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)