From 440212a154ba26a633fa1360ed1f7bb29b274026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Mon, 4 Jun 2018 13:38:26 +0200 Subject: [PATCH] Fix for newStringOfCap in VM (#7901) --- compiler/vmgen.nim | 3 ++- tests/vm/tvmmisc.nim | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 7ac3b5cf75..8a3c7e2e6e 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -844,7 +844,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mNewStringOfCap: # we ignore the 'cap' argument and translate it as 'newString(0)'. # eval n.sons[1] for possible side effects: - var tmp = c.genx(n.sons[1]) + c.freeTemp(c.genx(n.sons[1])) + var tmp = c.getTemp(n.sons[1].typ) c.gABx(n, opcLdImmInt, tmp, 0) if dest < 0: dest = c.getTemp(n.typ) c.gABC(n, opcNewStr, dest, tmp) diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim index 472660bc22..4af824cf47 100644 --- a/tests/vm/tvmmisc.nim +++ b/tests/vm/tvmmisc.nim @@ -82,3 +82,11 @@ block: assert fileExists("MISSINGFILE") == false assert dirExists("MISSINGDIR") == false + +# #7210 +block: + static: + proc f(size: int): int = + var some = newStringOfCap(size) + result = size + doAssert f(4) == 4 \ No newline at end of file