diff --git a/compiler/interface.go b/compiler/interface.go index 94a60f3d..beda21a6 100644 --- a/compiler/interface.go +++ b/compiler/interface.go @@ -161,7 +161,14 @@ func getTypeCodeName(t types.Type) string { panic("cgo unions are not allowed in interfaces") } for i := 0; i < t.NumFields(); i++ { - elems[i] = getTypeCodeName(t.Field(i).Type()) + embedded := "" + if t.Field(i).Embedded() { + embedded = "#" + } + elems[i] = embedded + t.Field(i).Name() + ":" + getTypeCodeName(t.Field(i).Type()) + if t.Tag(i) != "" { + elems[i] += "`" + t.Tag(i) + "`" + } } return "struct:" + "{" + strings.Join(elems, ",") + "}" default: diff --git a/testdata/interface.go b/testdata/interface.go index 69c3b32c..88b0944b 100644 --- a/testdata/interface.go +++ b/testdata/interface.go @@ -11,6 +11,10 @@ func main() { printItf(*thing) printItf(thing) printItf(Stringer(thing)) + printItf(struct{ n int }{}) + printItf(struct { + n int `foo:"bar"` + }{}) printItf(Number(3)) array := Array([4]uint32{1, 7, 11, 13}) printItf(array) @@ -47,6 +51,14 @@ func printItf(val interface{}) { println("is Thing:", val.String()) case *Thing: println("is *Thing:", val.String()) + case struct{ i int }: + println("is struct{i int}") + case struct{ n int }: + println("is struct{n int}") + case struct { + n int `foo:"bar"` + }: + println("is struct{n int `foo:\"bar\"`}") case Foo: println("is Foo:", val) default: diff --git a/testdata/interface.txt b/testdata/interface.txt index 3f398974..83ee80b0 100644 --- a/testdata/interface.txt +++ b/testdata/interface.txt @@ -7,6 +7,8 @@ is Foo: 18 is Thing: foo is *Thing: foo is *Thing: foo +is struct{n int} +is struct{n int `foo:"bar"`} is Doubler: 6 is Tuple: 1 7 11 13 Array len: 4