From 63cbc01628dd41365ccee6ef0413d63447f3d735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 8 Dec 2019 22:57:36 +0000 Subject: [PATCH] support anonymous fields better --- main.go | 7 +++++-- testdata/scripts/syntax.txt | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b83eb60..a9f796f 100644 --- a/main.go +++ b/main.go @@ -300,8 +300,12 @@ func transformGo(node ast.Node, info *types.Info) ast.Node { return true // unnamed remains unnamed } obj := info.ObjectOf(node) - switch obj.(type) { + // log.Printf("%#v %T", node, obj) + switch x := obj.(type) { case *types.Var: + if x.Embedded() { + obj = obj.Type().(*types.Named).Obj() + } case *types.Const: case *types.TypeName: case *types.Func: @@ -337,7 +341,6 @@ func transformGo(node ast.Node, info *types.Info) ast.Node { buildID = id } } - // log.Printf("%#v\n", node.Obj) node.Name = hashWith(buildID, node.Name) } return true diff --git a/testdata/scripts/syntax.txt b/testdata/scripts/syntax.txt index 8147e88..55c7240 100644 --- a/testdata/scripts/syntax.txt +++ b/testdata/scripts/syntax.txt @@ -5,8 +5,14 @@ cmp stderr main.stderr -- main.go -- package main +import "go/ast" + var V interface{} +type T struct{ + ast.Node +} + func main() { switch V := V.(type) { case int: