diff options
-rw-r--r-- | compiler/vmgen.nim | 2 | ||||
-rw-r--r-- | tests/vm/tnewseqofcap.nim | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index f084ab7ba..0c0c491e0 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -683,6 +683,8 @@ proc genNewSeq(c: PCtx; n: PNode) = proc genNewSeqOfCap(c: PCtx; n: PNode; dest: var TDest) = let t = n.typ + if dest < 0: + dest = c.getTemp(n.typ) let tmp = c.getTemp(n[1].typ) c.gABx(n, opcLdNull, dest, c.genType(t)) c.gABx(n, opcLdImmInt, tmp, 0) diff --git a/tests/vm/tnewseqofcap.nim b/tests/vm/tnewseqofcap.nim new file mode 100644 index 000000000..c61c3c485 --- /dev/null +++ b/tests/vm/tnewseqofcap.nim @@ -0,0 +1,19 @@ +discard """ + output: '''@["aaa", "bbb", "ccc"]''' +""" + + +const + foo = @["aaa", "bbb", "ccc"] + +proc myTuple: tuple[n: int, bar: seq[string]] = + result.n = 42 + result.bar = newSeqOfCap[string](foo.len) + for f in foo: + result.bar.add(f) + +# It works if you change the below `const` to `let` +const + (n, bar) = myTuple() + +echo bar \ No newline at end of file |