Skip to content

fmt.Printf("%p", x) does not work if x has a String method. #1024

@rogpeppe

Description

@rogpeppe
the following code prints "%p(string=hello)".

this is a direct consequence of the recent changes to
fmt to switch on type first, but it's not helpful behaviour
and it's not easy to work around without importing
reflect and rewriting fmtUintptrGetter.

might i suggest that fmt.printField only check for Stringer/GoStringer
when the verb can actually process a string.

package main
import "fmt"
type T struct{}
func main() { fmt.Printf("%p\n", &T{}) }
func (x *T) String() string { return "hello" }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions