-
Notifications
You must be signed in to change notification settings - Fork 18k
maps: inconsistent panic in Copy with nil dst #64390
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
It's not clear to me why the proposed behavior is any better than the current behavior. The old behavior is consistent with the built-in maps rule that nil maps panic only when written to. I don't think we can change the behavior now. This API has already been released and people may be depending on the old behavior, even if unspecified in the docs. |
I would have said the opposite; I find the proposed behavior more consistent with the built-in maps rule, but now I also understand your perspective. I'd suggest documenting the current behavior at this point; it's not quite evident without delving into the code. |
CC @eliben, @Deleplace. |
I agree with most of the arguments, though IMO any usage of Keeping and documenting the existing behaviour should be fine:
|
As far as I could see, there are two ways we can take:
Personally, I would prefer the second approach. The rationale behind this choice is that if we are copying, it is likely that we are allocating space in a new memory address if it does not exist yet. The function I can take that to solve, if you guys don't mind |
I don't think |
The
maps.Copy
function panics if the destination map isnil
and the source map is not empty (dst == nil && len(src) > 0
)This behavior is not currently documented.
I propose to panic if
dst
isnil
, independently fromsrc
, and document it. The updated behavior would beThe text was updated successfully, but these errors were encountered: