From ec64b006cf14e926ca9cd9f0dcee493c4fd2b188 Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Tue, 29 Sep 2020 09:22:04 +0200 Subject: [PATCH] fix: convert struct tags properly --- _test/struct58.go | 24 ++++++++++++++++++++++++ interp/type.go | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 _test/struct58.go diff --git a/_test/struct58.go b/_test/struct58.go new file mode 100644 index 00000000..9dca132d --- /dev/null +++ b/_test/struct58.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "reflect" +) + +type A struct { + Test string `tag:"test"` +} + +func main() { + a := A{} + t := reflect.TypeOf(a) + f, ok := t.FieldByName("Test") + if !ok { + return + } + + fmt.Println(f.Tag.Get("tag")) +} + +// Output: +// test diff --git a/interp/type.go b/interp/type.go index f644a25a..af4d9a80 100644 --- a/interp/type.go +++ b/interp/type.go @@ -604,7 +604,7 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) { t.field = append(t.field, structField{name: fieldName(c.child[0]), embed: true, typ: typ}) incomplete = incomplete || typ.incomplete case len(c.child) == 2 && c.child[1].kind == basicLit: - tag := c.child[1].rval.String() + tag := vString(c.child[1].rval) typ, err := nodeType(interp, sc, c.child[0]) if err != nil { return nil, err @@ -615,7 +615,7 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) { var tag string l := len(c.child) if c.lastChild().kind == basicLit { - tag = c.lastChild().rval.String() + tag = vString(c.lastChild().rval) l-- } typ, err := nodeType(interp, sc, c.child[l-1])