-
Notifications
You must be signed in to change notification settings - Fork 18k
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: formatting of reflect.Value items inconsistent with documentation #16015
Comments
There is a trivial fix to this that solves the test case but won't work in general. The code says
We could instead call
which would extract the interface and print that. This works but only if the value being printed was not acquired by using Value.Field of an unexported field. We could write
and maybe that's the best we can do. Another possibility, maybe the right one, is to tweak the if at the top of printValue to know that the handle-methods check hasn't been done yet. Needs thought. |
I think the
|
Added the depth check when refactoring reflect value printing https://go-review.googlesource.com/#/c/20923/. As far as i recall currently: If only the depth check is removed handleMethods is called twice for the default branch of printArg.
So the depth check addresses the CL comment about "slows down a very common operation" and to not slow down printValue for depth 0 either. I will take a look for go 1.8 how we can ideally keep the performance for Stringer and still call handleMethods consistently once for reflect values. |
@martisch Have you had a chance to look at this? |
Thanks for bringing this back to my attention. Was on vacation in september and sidetracked by some other patches. (I also was not able to assign myself to golang issues) I will do some measurements again and send a proposal CL with tests within a week so we have this fixed for 1.8. |
CL https://golang.org/cl/30753 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
go version
)?1.6.2
go env
)?playground
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
From sbkim in https://groups.google.com/d/topic/golang-nuts/3DofSQIIF2w/discussion:
https://golang.org/pkg/fmt/ says:
So, in the following program (https://play.golang.org/p/V4H-vkjoE5):
I expect the first fmt.Printf call to substitute the concrete value of v, which is SpecialInt(73), invoke the String() method on it, and print "SpecialInt(73)". However, it just prints "73". On the contrary, the second fmt.Printf call (correctly) prints "SpecialInt(73)".
Is there anything I'm missing here, or maybe something wrong with the Go documentation or implementation?
SpecialInt(73)
SpecialInt(73)
73
SpecialInt(73)
The text was updated successfully, but these errors were encountered: