This commit is contained in:
flywind 2020-11-02 17:27:48 +08:00 • committed by GitHub
commit 558115fa29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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)

19
tests/vm/tnewseqofcap.nim Normal file
View file

@ -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