support anonymous fields better

pull/22/head
Daniel Martí 5 years ago
parent a87002e662
commit 63cbc01628

@ -300,8 +300,12 @@ func transformGo(node ast.Node, info *types.Info) ast.Node {
return true // unnamed remains unnamed return true // unnamed remains unnamed
} }
obj := info.ObjectOf(node) obj := info.ObjectOf(node)
switch obj.(type) { // log.Printf("%#v %T", node, obj)
switch x := obj.(type) {
case *types.Var: case *types.Var:
if x.Embedded() {
obj = obj.Type().(*types.Named).Obj()
}
case *types.Const: case *types.Const:
case *types.TypeName: case *types.TypeName:
case *types.Func: case *types.Func:
@ -337,7 +341,6 @@ func transformGo(node ast.Node, info *types.Info) ast.Node {
buildID = id buildID = id
} }
} }
// log.Printf("%#v\n", node.Obj)
node.Name = hashWith(buildID, node.Name) node.Name = hashWith(buildID, node.Name)
} }
return true return true

@ -5,8 +5,14 @@ cmp stderr main.stderr
-- main.go -- -- main.go --
package main package main
import "go/ast"
var V interface{} var V interface{}
type T struct{
ast.Node
}
func main() { func main() {
switch V := V.(type) { switch V := V.(type) {
case int: case int:

Loading…
Cancel
Save