-
Notifications
You must be signed in to change notification settings - Fork 18k
spec: clarify that make
does not panic for negative capacity hint
#53219
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
Comments
make
does not panic for negative capacity hint
cc @golang/runtime |
Given that a negative However, I don't think you're wrong about the spec, it does suggest what you say. I'm not sure what the right answer is here. CC @ianlancetaylor and @griesemer |
I think this is sentence is intended to describe making slices, not maps. For maps, there is no See #46909 #24308. The consensus there seems to be that with maps, there is a reasonable way to proceed when |
make
does not panic for negative capacity hintmake
does not panic for negative capacity hint
Change https://go.dev/cl/411919 mentions this issue: |
What version of Go are you using (
go version
)?The spec for Go1.18
https://go.dev/ref/spec (Version of March 10, 2022)
Does this issue reproduce with the latest release?
Yes.
What did you do?
I read the following sentence from the spec, and run the following code. (Go playground link is here: https://go.dev/play/p/whw_4ZBzsx_K)
What did you expect to see?
I expect the program to panic, because
n
is negative and the sentence does not exclude the casemake
is used for creating a map.What did you see instead?
It did not panic.
I think the spec should clarify that
make(map[int]int, n)
for negativen
does not (necessarily) cause run-time panic.The text was updated successfully, but these errors were encountered: