1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:48:32 -06:00

go/types: add missing nil check in Info.TypeOf

Also use type assertions in a more defensive
way (check for != nil rather than ok).

LGTM=dsymonds, adonovan
R=adonovan, dsymonds
CC=golang-codereviews
https://golang.org/cl/169480043
This commit is contained in:
Robert Griesemer 2014-11-12 15:39:43 -08:00
parent b8a5fcfcec
commit 932b62a02f

View File

@ -215,8 +215,10 @@ func (info *Info) TypeOf(e ast.Expr) Type {
if t, ok := info.Types[e]; ok {
return t.Type
}
if id, ok := e.(*ast.Ident); ok {
return info.ObjectOf(id).Type()
if id, _ := e.(*ast.Ident); id != nil {
if obj := info.ObjectOf(id); obj != nil {
return obj.Type()
}
}
return nil
}
@ -230,7 +232,7 @@ func (info *Info) TypeOf(e ast.Expr) Type {
// Precondition: the Uses and Defs maps are populated.
//
func (info *Info) ObjectOf(id *ast.Ident) Object {
if obj, ok := info.Defs[id]; ok {
if obj, _ := info.Defs[id]; obj != nil {
return obj
}
return info.Uses[id]