fixes #17197; fixes #22560; fixes the dest of newSeqOfCap in refc (#22594)

(cherry picked from commit 5bd1afc3f9)
This commit is contained in:
ringabout
2023-08-31 19:04:32 +08:00
committed by narimiran
parent 2d529edf3e
commit 4fc535fbd6
2 changed files with 18 additions and 0 deletions

View File

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

View File

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