Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #19314 - fixing broken DoublyLinkedList after adding empty DoublyLinkedList #19315

Merged
merged 2 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/pure/collections/lists.nim
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,12 @@ proc addMoved*[T](a, b: var DoublyLinkedList[T]) {.since: (1, 5, 1).} =
assert s == [0, 1, 0, 1, 0, 1]

if b.head != nil:
b.head.prev = a.tail
if a.tail != nil:
a.tail.next = b.head
a.tail = b.tail
if a.head == nil:
a.head = b.head
if a.head == nil:
a.head = b.head
else:
b.head.prev = a.tail
a.tail.next = b.head
a.tail = b.tail
if a.addr != b.addr:
b.head = nil
b.tail = nil
Expand Down
12 changes: 12 additions & 0 deletions tests/stdlib/tlists.nim
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ template main =
doAssert a.toSeq == @[1]
a.add(2)
doAssert a.toSeq == @[1, 2]

block issue19314: # add (appends a shallow copy)
var a: DoublyLinkedList[int]
var b: DoublyLinkedList[int]

doAssert a.toSeq == @[]
a.add(1)
doAssert a.toSeq == @[1]
a.add(b)
doAssert a.toSeq == @[1]
a.add(2)
doAssert a.toSeq == @[1, 2]

static: main()
main()