@@ -252,10 +252,41 @@ func (ctx *fileContext) GetTypeId(typ ast.Expr) (x Identity, isPointer bool, isS
252252 if tinfo , ok := ctx .pkgTypeInfo .Types [typ ]; ok {
253253 return ctx .getIdFromType (tinfo .Type )
254254 } else {
255- panic ("cannot find type info for " + string (ctx .GetRawContent (typ )))
255+ // NOTICE: for unloaded type, we only mock the type name
256+ fmt .Fprintf (os .Stderr , "cannot find type info for %s\n " , ctx .GetRawContent (typ ))
257+ return ctx .mockType (typ )
256258 }
257259}
258260
261+ func (ctx * fileContext ) mockType (typ ast.Expr ) (x Identity , isPointer bool , isStdOrBuiltin bool ) {
262+ switch ty := typ .(type ) {
263+ case * ast.StarExpr :
264+ id , _ , std := ctx .mockType (ty .X )
265+ return id , true , std
266+ case * ast.CallExpr :
267+ // try get func type
268+ id , _ , std := ctx .mockType (ty .Fun )
269+ return id , false , std
270+ case * ast.SelectorExpr :
271+ // try get import path
272+ switch xx := ty .X .(type ) {
273+ case * ast.Ident :
274+ impt , mod , err := ctx .imports .GetImportPath (xx .Name , "" )
275+ if err != nil {
276+ goto fallback
277+ }
278+ return NewIdentity (mod , PkgPath (impt ), ty .Sel .Name ), false , false
279+ case * ast.SelectorExpr :
280+ // recurse
281+ id , _ , std := ctx .mockType (xx )
282+ return NewIdentity (id .ModPath , id .PkgPath , ty .Sel .Name ), false , std
283+ }
284+ }
285+
286+ fallback:
287+ return NewIdentity ("UNLOADED" , ctx .pkgPath , string (ctx .GetRawContent (typ ))), false , true
288+ }
289+
259290func (ctx * fileContext ) collectFields (fields []* ast.Field , m * []Dependency ) {
260291 for _ , fieldDecl := range fields {
261292 id , _ , isStdOrBuiltin := ctx .GetTypeId (fieldDecl .Type )
0 commit comments