Skip to content

Commit

Permalink
fix: Pkg() may return nil (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane authored Apr 7, 2023
1 parent ad858d7 commit 9944e5d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions musttag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9944e5d

Please sign in to comment.