Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
fmt: compound object rules don't seem to apply recursively #28625
It is specifically said that these rules apply recursively. However, take a look at this playground link: https://play.golang.org/p/CbrniH9q45I
It currently prints:
But I'd expect it to print:
Reading the docs carefully again, I can't find a reason why only top-level pointers would follow the "pointer to above" rule that's clearly documented.
It seems to me like either the code is wrong, or the docs need clarification. If only top-level pointers are supposed to follow the "pointer to above" rule, that should be made clear in the rules.
This issue is split from #27672. I initially thought this was a bug in vet, but then started wondering if this was a bug in fmt instead.
I think the issues are slightly different (the other one started as %d not applying to pointers, which IIRC is WAI according to the documentation). So happy if this stays open and we can discuss if we should just update the documentation. With the other issue i wanted to reference the note that the implementation is deliberately not following pointers to arbitrary depth as there could be loops in pointer chains.
Those look like rules for
Which makes a bit more sense. Since it's a pointer to a pointer,
Pointers to compound objects (structs, slices, arrays, maps) are only followed by fmt if the pointer is at the top level of an argument. This is to minimise the chances of fmt running into loops. However, vet did not follow this rule. It likely doesn't help that fmt does not document that restriction well, which is being tracked in #28625. Updates #27672. Change-Id: Ie9bbd9b974eda5ab9a285986d207ef92fca4453e Reviewed-on: https://go-review.googlesource.com/c/147997 Run-TryBot: Daniel Martí <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Alan Donovan <firstname.lastname@example.org>