diff options
author | Clyybber <darkmine956@gmail.com> | 2020-07-15 23:33:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-15 23:33:58 +0200 |
commit | 282128ab66b6391c4ab9bc76cd19a63a5bce16f8 (patch) | |
tree | 7a17bb4da894672ee0b2ed6ce98990a962414f2a | |
parent | 617c1f16d70657fbe4a69d76a2f00b84560af15a (diff) | |
download | Nim-282128ab66b6391c4ab9bc76cd19a63a5bce16f8.tar.gz |
Fix #14994 (#14996)
* Fix #14994 * Revert misplaced "optimization" * Typo
-rw-r--r-- | lib/pure/collections/sequtils.nim | 3 | ||||
-rw-r--r-- | lib/system/seqs_v2.nim | 1 | ||||
-rw-r--r-- | tests/arc/tarcmisc.nim | 14 |
3 files changed, 17 insertions, 1 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index f101d508e..51d8ade85 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -527,7 +527,8 @@ proc insert*[T](dest: var seq[T], src: openArray[T], pos = 0) = assert dest == outcome var j = len(dest) - 1 - var i = len(dest) + len(src) - 1 + var i = j + len(src) + if i == j: return dest.setLen(i + 1) # Move items after `pos` to the end of the sequence. diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index 4001e97c3..3c94a03f9 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -82,6 +82,7 @@ proc shrink*[T](x: var seq[T]; newLen: Natural) = proc grow*[T](x: var seq[T]; newLen: Natural; value: T) = let oldLen = x.len + #sysAssert newLen >= x.len, "invalid newLen parameter for 'grow'" if newLen <= oldLen: return var xu = cast[ptr NimSeqV2[T]](addr x) if xu.p == nil or xu.p.cap < newLen: diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index 2d7e6b455..56aa3ec3b 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -21,6 +21,8 @@ whiley ends :( (x: "9") (x: "10") 0 +new line before - @['a'] +new line after - @['a'] closed destroying variable: 20 destroying variable: 10 @@ -243,3 +245,15 @@ l.setParent(l) # bug #14968 import times let currentTime = now().utc + + +# bug #14994 +import sequtils +var newLine = @['a'] +let indent = newSeq[char]() + +echo "new line before - ", newline + +newline.insert(indent, 0) + +echo "new line after - ", newline |