mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-02 03:43:41 +00:00
…0) of 1-length seq
fixes #26134
(cherry picked from commit dcec8e1cd1)
This commit is contained in:
@@ -1257,7 +1257,9 @@ proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||
a.del(2)
|
||||
assert a == @[10, 11, 14, 13]
|
||||
let xl = x.len - 1
|
||||
movingCopy(x[i], x[xl])
|
||||
# Avoid moving the element onto itself when deleting the last item.
|
||||
if i != xl:
|
||||
movingCopy(x[i], x[xl])
|
||||
setLen(x, xl)
|
||||
|
||||
proc insert*[T](x: var seq[T], item: sink T, i = 0.Natural) {.noSideEffect.} =
|
||||
|
||||
24
tests/stdlib/t26134.nim
Normal file
24
tests/stdlib/t26134.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
discard """
|
||||
matrix: "--mm:orc --undef:nimPreviewNonVarDestructor"
|
||||
output: "hello"
|
||||
"""
|
||||
|
||||
# bug #26134
|
||||
|
||||
type MyObject = object
|
||||
|
||||
proc `=destroy`(v: var MyObject) =
|
||||
echo "hello"
|
||||
|
||||
proc remove(v: var seq[MyObject]) =
|
||||
v.del(0)
|
||||
|
||||
proc aaa(v: var seq[MyObject], i: sink MyObject) =
|
||||
v.add(i)
|
||||
|
||||
proc main =
|
||||
var v: seq[MyObject]
|
||||
v.aaa(MyObject())
|
||||
v.remove()
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user