Fix the range of destroyed elements when shrinking a seq (#11785)
This commit is contained in:
parent
a5d6080a81
commit
903d06bab8
1 changed files with 1 additions and 1 deletions
|
|
@ -138,7 +138,7 @@ proc shrink*[T](x: var seq[T]; newLen: Natural) =
|
||||||
mixin `=destroy`
|
mixin `=destroy`
|
||||||
sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
||||||
when not supportsCopyMem(T):
|
when not supportsCopyMem(T):
|
||||||
for i in countdown(x.len - 1, newLen - 1):
|
for i in countdown(x.len - 1, newLen):
|
||||||
`=destroy`(x[i])
|
`=destroy`(x[i])
|
||||||
# XXX This is wrong for const seqs that were moved into 'x'!
|
# XXX This is wrong for const seqs that were moved into 'x'!
|
||||||
cast[ptr NimSeqV2[T]](addr x).len = newLen
|
cast[ptr NimSeqV2[T]](addr x).len = newLen
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue