func main() {
l := list.New()
l.PushBack(1)
front := l.Front()
l.Init()
fmt.Println("list len:", l.Len(), "front is nil:", l.Front() == nil)
l.Remove(front)
fmt.Println("list len:", l.Len(), "front is nil:", l.Front() == nil)
}
What did you see happen?
list len: 0 front is nil: true
list len: -1 front is nil: false
What did you expect to see?
I expected that after reinitializing the list with l.Init(), attempting to remove an element that was previously in the list would either do nothing or result in a runtime error, and the list length would remain at 0.
Go version
go version go1.22.5 linux/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/OK0kMoF1XR9
What did you see happen?
list len: 0 front is nil: true list len: -1 front is nil: false
What did you expect to see?
I expected that after reinitializing the list with l.Init(), attempting to remove an element that was previously in the list would either do nothing or result in a runtime error, and the list length would remain at 0.