From 7f3efa1eb53f0fc1e1b1c496e1b73c4d5b46ad78 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Mon, 17 Dec 2018 21:20:21 -0800 Subject: [PATCH] fix nil pointer dereference --- build/context.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build/context.go b/build/context.go index 84353ee..3dbdbf4 100644 --- a/build/context.go +++ b/build/context.go @@ -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) }