aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2014-11-12 15:39:43 -0800
committerRobert Griesemer <gri@golang.org>2014-11-12 15:39:43 -0800
commit932b62a02f87862730a919fcb6f627010bfdecd9 (patch)
tree6311a864dc48e125d0430de42a264cf5dc3c5c2b /go
parentb8a5fcfcec6ee118953b8f5294652e0c7c793dfb (diff)
downloadtools-932b62a02f87862730a919fcb6f627010bfdecd9.tar.gz
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
Diffstat (limited to 'go')
-rw-r--r--go/types/api.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/go/types/api.go b/go/types/api.go
index 908b0f0..bfdcccb 100644
--- a/go/types/api.go
+++ b/go/types/api.go
@@ -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]