From 9d710712becfe5ee08c7e9d0940ddd14145f77f7 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Sat, 17 Mar 2018 12:20:55 +1100 Subject: [PATCH] add embedding support --- codegen/util.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/codegen/util.go b/codegen/util.go index 5f1b7328312..f7ecc618fee 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -82,12 +82,42 @@ func findMethod(typ *types.Named, name string) *types.Func { return method } } + + if s, ok := typ.Underlying().(*types.Struct); ok { + for i := 0; i < s.NumFields(); i++ { + field := s.Field(i) + if !field.Anonymous() { + continue + } + + if named, ok := field.Type().(*types.Named); ok { + if f := findMethod(named, name); f != nil { + return f + } + } + } + } + return nil } func findField(typ *types.Struct, name string) *types.Var { for i := 0; i < typ.NumFields(); i++ { field := typ.Field(i) + if field.Anonymous() { + if named, ok := field.Type().(*types.Struct); ok { + if f := findField(named, name); f != nil { + return f + } + } + + if named, ok := field.Type().Underlying().(*types.Struct); ok { + if f := findField(named, name); f != nil { + return f + } + } + } + if !field.Exported() { continue }