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

container/list: if list does not have any element, invoke Remove will panic #23372

Closed
Hu-Jiang opened this issue Jan 8, 2018 · 5 comments
Closed

Comments

@Hu-Jiang
Copy link

Hu-Jiang commented Jan 8, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Jiang_Hu/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t0/wz8wcf3s7_zfl024tzh3m0bc0000gn/T/go-build810890647=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

l := new(list.List)
l.PushFront(1)
fmt.Println("remove value:", l.Remove(l.Front()))
fmt.Println("remove value:", l.Remove(l.Front()))

code link: https://play.golang.org/p/8kwOyncS3_q

What did you expect to see?

do not panic, just do nothing

What did you see instead?

@cznic
Copy link
Contributor

cznic commented Jan 8, 2018

I think this is working as intended. One should not pass nil to Remove. Putting the check into Remove will slow down all places where the test is not necessary.

@Hu-Jiang
Copy link
Author

Hu-Jiang commented Jan 8, 2018

so when i want to remove one element, i need to judge whether it's nil? This way is also slowly.

@cznic
Copy link
Contributor

cznic commented Jan 8, 2018

Yes, but now it's only where necessary: https://play.golang.org/p/JMngsvc22eq

@gopherbot
Copy link

Change https://golang.org/cl/86676 mentions this issue: container/list: document nil values more

@bradfitz
Copy link
Contributor

bradfitz commented Jan 8, 2018

@cznic is correct that this is working as intended. It also helps catch programmer errors. I've sent a documentation change at least.

@golang golang locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants