Repository: JuliaCollections/DataStructures.jl (julia)

Issue:
append! broken for MutableLinkedLists?
Hi! I been having a few problems with the MutableLinkedList type, (infinite loops and segfaults).
I've tested up to version 18.9 and reduced the problems to this minimal example:

```
julia> using DataStructures
julia> l1 = MutableLinkedList{Int}(1:5...);
julia> l2 = MutableLinkedList{Int}(10:15...);
julia> append!(l1,l2);
julia> collect(l1)
ERROR: 
signal (11): Segmentation fault
in expression starting at none:0
```

Pull request description:
Fixes #725 

The logic for making the end of the appended list point to the original list's terminal node was wrong.

Patch:
diff --git a/src/mutable_list.jl b/src/mutable_list.jl
index 13b8827b7..6559539b0 100644
--- a/src/mutable_list.jl
+++ b/src/mutable_list.jl
@@ -151,8 +151,8 @@ function Base.setindex!(l::MutableLinkedList{T}, data, idx::Int) where T
 end
 
 function Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T
-    l1.node.prev.next = l2.node.next
-    l2.node.next.prev = l1.node.prev
+    l1.node.prev.next = l2.node.next # l1's last's next is now l2's first
+    l2.node.prev.next = l1.node # l2's last's next is now l1.node
     l1.len += length(l2)
     return l1
 end


Test patch:
diff --git a/test/test_mutable_list.jl b/test/test_mutable_list.jl
index b5f51aa8d..36fb50fe5 100644
--- a/test/test_mutable_list.jl
+++ b/test/test_mutable_list.jl
@@ -98,9 +98,11 @@
                     l2 = MutableLinkedList{Int}(n+1:2n...)
                     append!(l, l2)
                     @test l == MutableLinkedList{Int}(1:2n...)
+                    @test collect(l) == collect(MutableLinkedList{Int}(1:2n...))
                     l3 = MutableLinkedList{Int}(1:n...)
                     append!(l3, n+1:2n...)
                     @test l3 == MutableLinkedList{Int}(1:2n...)
+                    @test collect(l3) == collect(MutableLinkedList{Int}(1:2n...))
                 end
 
                 @testset "delete" begin