fix nil pointer dereference

This commit is contained in:
Michael McLoughlin
2018-12-17 21:20:21 -08:00
parent 1033aa4f9c
commit 7f3efa1eb5

View File

@@ -2,6 +2,7 @@ package build
import ( import (
"errors" "errors"
"go/types"
"github.com/mmcloughlin/avo" "github.com/mmcloughlin/avo"
"github.com/mmcloughlin/avo/gotypes" "github.com/mmcloughlin/avo/gotypes"
@@ -53,7 +54,7 @@ func (c *Context) Signature(s *gotypes.Signature) {
} }
func (c *Context) SignatureExpr(expr string) { func (c *Context) SignatureExpr(expr string) {
s, err := gotypes.ParseSignatureInPackage(c.pkg.Types, expr) s, err := gotypes.ParseSignatureInPackage(c.types(), expr)
if err != nil { if err != nil {
c.AddError(err) c.AddError(err)
return return
@@ -61,6 +62,13 @@ func (c *Context) SignatureExpr(expr string) {
c.Signature(s) c.Signature(s)
} }
func (c *Context) types() *types.Package {
if c.pkg == nil {
return nil
}
return c.pkg.Types
}
func (c *Context) Instruction(i *avo.Instruction) { func (c *Context) Instruction(i *avo.Instruction) {
c.activefunc().AddNode(i) c.activefunc().AddNode(i)
} }