From 4fc535fbd6690f36c81dbd142b3562ba5f389cfa Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:04:32 +0800 Subject: [PATCH] fixes #17197; fixes #22560; fixes the dest of newSeqOfCap in refc (#22594) (cherry picked from commit 5bd1afc3f9716fed833b7bd251ee45479b78a950) --- compiler/ccgexprs.nim | 1 + tests/collections/tseq.nim | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 14b291b570..524029000f 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1447,6 +1447,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = getSeqPayloadType(p.module, seqtype), ]) else: + if d.k == locNone: getTemp(p, e.typ, d, needsInit=false) # bug #22560 putIntoDest(p, d, e, ropecg(p.module, "($1)#nimNewSeqOfCap($2, $3)", [ getTypeDesc(p.module, seqtype), diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim index a7a0c724ec..8a42802f0f 100644 --- a/tests/collections/tseq.nim +++ b/tests/collections/tseq.nim @@ -214,3 +214,20 @@ for i in 0..100: var test = newSeqOfCap[uint32](1) test.setLen(1) doAssert test[0] == 0, $(test[0], i) + + +# bug #22560 +doAssert len(newSeqOfCap[int](42)) == 0 + +block: # bug #17197 + type Matrix = seq[seq[int]] + + proc needlemanWunsch(sequence1: string, sequence2: string, gap_penal: int8, match: int8, indel_penal: int8): bool = + let seq2_len = sequence2.len + + var grid: Matrix + for i in sequence1: + grid.add(newSeqOfCap[seq[int]](seq2_len)) + result = true + + doAssert needlemanWunsch("ABC", "DEFG", 1, 2, 3)