diff options
author | rockcavera <rockcavera@gmail.com> | 2021-12-30 17:52:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-30 21:52:48 +0100 |
commit | dc5c88ca79e871aefa76c7fefae4282c639a3283 (patch) | |
tree | 5d7acf77abf325b2592c899205512cb544addb78 /tests/stdlib | |
parent | 23d64be860958fb7149baed44f6e493394950d69 (diff) | |
download | Nim-dc5c88ca79e871aefa76c7fefae4282c639a3283.tar.gz |
Fix #19297 - fixing broken list after adding empty list (#19299)
* Update lists.nim * Update tlists.nim * removed check `if b.tail != nil` The tail of the list being null it is still possible to retrieve its end by going through all nodes from the head. So checking for null from `b.tail` is unnecessary. However, setting `a.tail = b.tail` only if `a.head != nil`, so you don't break a good list with an already broken one.
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/tlists.nim | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/stdlib/tlists.nim b/tests/stdlib/tlists.nim index 54fa8b24f..2f6d5ee6a 100644 --- a/tests/stdlib/tlists.nim +++ b/tests/stdlib/tlists.nim @@ -233,6 +233,18 @@ template main = doAssert l.toSeq == [1] doAssert l.remove(l.head) == true doAssert l.toSeq == [] + + block issue19297: # add (appends a shallow copy) + var a: SinglyLinkedList[int] + var b: SinglyLinkedList[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() |