-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: inconsistent pointer formatting with b/d/o/x/X verbs #65753
Comments
seems to work with primitive types like pointers to bool/string/int, but not for composite types like slices, maps, and structs. cc @robpike |
The cited documentation is irrelevant to the issue, as you can see if you try the program without taking the address of the struct: you see the same behavior. Now the question is, should the formats recur into the fields of a struct? They do not, and doing so would rarely be the right thing to do. Whether the documentation needs work here I'm not sure, but the paragraph you cite is irrelevant, as I said. |
Have a look at https://go.dev/play/p/HnO93o9-oao The particular problem cited in this issue is that formats propagate for integer values but not strings, although as the example shows it would be rarely useful for them to do so. That's probably fixable, but also probably not worthwhile. |
the format also works for books and strings though |
Sorry, there might be a misunderstanding. The original title for the report was "fmt: Pointer formatting behavior doesn't match documentation". I don't have an opinion how the code should behave, just it doesn't behave as documented.
A struct value is not a pointer; so the section "Pointer:" doesn't apply, and the section below that called "For compound objects, ..." applies, that's consistent. If you think the code is working as intended, I'm fine with that. In that case I suggest the following changes to the documentation (emphasis on the changes):
and below
|
Go version
Playground Go 1.22
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/ivQo1wTK4NM
What did you see happen?
0xc000014070
&{%!b(string=baz)}
&{%!d(string=baz)}
&{%!o(string=baz)}
&{62617a}
&{62617A}
What did you expect to see?
https://pkg.go.dev/fmt#hdr-Printing for go1.22.0 states:
Either the documentation should be fixed or the behavior of fmt.
The text was updated successfully, but these errors were encountered: