fixes #26134; del(seq) performs self-assignment and =destroy for del(… (#26138)

…0) of 1-length seq

fixes #26134

(cherry picked from commit dcec8e1cd1)
This commit is contained in:
ringabout
2026-08-29 20:41:36 +08:00
committed by narimiran
parent dad4e388b8
commit d6d7653f25
2 changed files with 27 additions and 1 deletions

24
tests/stdlib/t26134.nim Normal file
View 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()