From 98bcbfbab73cde8019079d9b7397a9656cac06c0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sat, 25 May 2013 10:04:20 -0700 Subject: [PATCH] go.tools/ssa: print identifer location if not found in TypeInfo R=adonovan, r CC=golang-dev https://golang.org/cl/9703044 --- ssa/builder.go | 1 + ssa/typeinfo.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ssa/builder.go b/ssa/builder.go index 37f71f0a..1f215778 100644 --- a/ssa/builder.go +++ b/ssa/builder.go @@ -2471,6 +2471,7 @@ func (b *Builder) membersFromDecl(pkg *Package, decl ast.Decl) { // func (b *Builder) typecheck(importPath string, files []*ast.File) (*types.Package, *TypeInfo, error) { info := &TypeInfo{ + fset: b.Prog.Files, types: make(map[ast.Expr]types.Type), idents: make(map[*ast.Ident]types.Object), constants: make(map[ast.Expr]*Literal), diff --git a/ssa/typeinfo.go b/ssa/typeinfo.go index 0f8cbd5a..153c2fbc 100644 --- a/ssa/typeinfo.go +++ b/ssa/typeinfo.go @@ -7,11 +7,13 @@ import ( "code.google.com/p/go.tools/go/types" "fmt" "go/ast" + "go/token" ) // TypeInfo contains information provided by the type checker about // the abstract syntax for a single package. type TypeInfo struct { + fset *token.FileSet types map[ast.Expr]types.Type // inferred types of expressions constants map[ast.Expr]*Literal // values of constant expressions idents map[*ast.Ident]types.Object // canonical type objects for named entities @@ -51,7 +53,7 @@ func (info *TypeInfo) ObjectOf(id *ast.Ident) types.Object { if obj, ok := info.idents[id]; ok { return obj } - panic(fmt.Sprintf("no types.Object for ast.Ident %s @ %p", id.Name, id)) + panic(fmt.Sprintf("no types.Object for ast.Ident %s @ %s", id.Name, info.fset.Position(id.Pos()))) } // IsType returns true iff expression e denotes a type.