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

fmt: does not differentiate nil map/slice from their empty value #8372

Closed
gopherbot opened this issue Jul 15, 2014 · 4 comments
Closed

fmt: does not differentiate nil map/slice from their empty value #8372

gopherbot opened this issue Jul 15, 2014 · 4 comments

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 15, 2014

by jbjcalmels:

What does 'go version' print?
go1.3

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. http://play.golang.org/p/_yhucaTieJ

What happened?
[]
[]
map[]
map[]

What should have happened instead?
<nil>
[]
<nil>
map[]

Please provide any additional information below.

Attached a patch to fix the issue (it may not cover all the corner cases though)

Attachments:

  1. print.patch (788 bytes)
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 15, 2014

Comment 1:

The nil value for slice and map types acts in most ways like the empty value.  There is
no particular reason to treat them differently in fmt.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Jul 15, 2014

Comment 2 by jbjcalmels:

So "%#v" distinguishes the two but "%v" should not ?
(http://play.golang.org/p/aVQX5ZNpPF)
@minux
Copy link
Member

@minux minux commented Jul 16, 2014

Comment 3:

that's right.
because "%#v" will print a Go-syntax representation of the value.
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Jul 16, 2014

Comment 4 by jbjcalmels:

Ok, I thought it would be more consistent to allow quick visualization of data without
relying on the verbosity of "%#v" (e.g http://play.golang.org/p/muxdTst3YO, good luck
finding the empty one)
Thanks anyway !
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.