Closed forchid closed 1 month ago
SinglyLinkedList
s are object
s which are value types, their contents which are SinglyLinkedNode
are reference types. The actual data is stored in the SinglyLinkedNode
but the tail node is stored in the SinglyLinkedList
object for performance, in this case the tail node is updated for sa
but not sb
.
You can turn sa
into a ref SinglyLinkedList
to get the desired behavior, but maybe the stdlib should offer the API for this via newSinglyLinkedList
and the same operations for ref SinglyLinkedList
as SinglyLinkedList
the same way tables do. At the very least this behavior should be documented, since it's unlike the other collection types which are entirely value types.
No bug here and linked lists always have surprising aliasing behavior, this is widely known.
The test source
Nim Version
active boot switches: -d:release
ds>%nim20_home%\bin\nim -v Nim Compiler Version 2.0.8 [Windows: amd64] Compiled at 2024-07-03 Copyright (c) 2006-2023 by Andreas Rumpf
active boot switches: -d:release
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response