From e0fc56f0f4fbf0d26146ece188b9164a2b997053 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 28 Mar 2023 13:45:38 +0300 Subject: [PATCH] fix: Pkg() may return nil --- musttag.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/musttag.go b/musttag.go index 0a4173f..9868b4a 100644 --- a/musttag.go +++ b/musttag.go @@ -198,8 +198,11 @@ func (c *checker) parseStructType(t types.Type, pos token.Pos) (*structType, boo switch t := t.(type) { case *types.Named: // a struct of the named type. - pkg := t.Obj().Pkg().Path() - if _, ok := c.mainModule[pkg]; !ok { + pkg := t.Obj().Pkg() // may be nil; see issue #38. + if pkg == nil { + return nil, false + } + if _, ok := c.mainModule[pkg.Path()]; !ok { return nil, false } s, ok := t.Underlying().(*types.Struct)