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