davecgh / go-spew

Implements a deep pretty printer for Go data structures to aid in debugging
ISC License
6.05k stars 364 forks source link

Override String function not works with anonymous struct param #142

Open rsgok opened 2 years ago

rsgok commented 2 years ago

example code

func main() {
    a := A{
        Tag: "tag-A",
        Num: 1,
        InA: InA{
            Id:   100,
            Type: "test",
        },
    }
    spew.Dump(a)
}

type A struct {
    Tag string
    Num int
    InA
}

type InA struct {
    Id   int
    Type string
}

func (t InA) String() string {
    return t.Type
}

unexpected output

(main.A) test
rsgok commented 2 years ago

and if struct member not anonymous, go-spew works