1
0
mirror of https://github.com/golang/go synced 2024-11-18 02:04:45 -07:00

cmd/vet: -lostcancel: fix crash in ill-typed code

Fixes golang/go#19656

Change-Id: Ied20d3f25b6e147cc693a1dd1aeb9480adc6687e
Reviewed-on: https://go-review.googlesource.com/38405
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Alan Donovan 2017-03-22 12:38:09 -04:00
parent b029e94344
commit 3b39f523e1

View File

@ -104,7 +104,11 @@ func checkLostCancel(f *File, node ast.Node) {
var sig *types.Signature
switch node := node.(type) {
case *ast.FuncDecl:
sig, _ = f.pkg.defs[node.Name].Type().(*types.Signature)
obj := f.pkg.defs[node.Name]
if obj == nil {
return // type error (e.g. duplicate function declaration)
}
sig, _ = obj.Type().(*types.Signature)
g = cfg.New(node.Body, mayReturn)
case *ast.FuncLit:
sig, _ = f.pkg.types[node.Type].Type.(*types.Signature)