diff --git a/ssa/builder.go b/ssa/builder.go index ddda130b93..e551542e4e 100644 --- a/ssa/builder.go +++ b/ssa/builder.go @@ -826,10 +826,10 @@ func (b *Builder) expr(fn *Function, e ast.Expr) Value { obj := fn.Pkg.ObjectOf(e) // Global or universal? if v, ok := b.lookup(fn.Pkg, obj); ok { - if objKind(obj) == ast.Var { - v = emitLoad(fn, v) // var (address) + if _, ok := obj.(*types.Var); ok { + return emitLoad(fn, v) // var (address) } - return v + return v // (func) } // Local? return emitLoad(fn, fn.lookup(obj, false)) // var (address) @@ -2560,8 +2560,6 @@ func (b *Builder) createPackageImpl(typkg *types.Package, importPath string, fil if len(files) > 0 { // Go source package. - // TODO(gri): make it a typechecker error for there to - // be duplicate (e.g.) main functions in the same package. for _, file := range p.Files { for _, decl := range file.Decls { b.membersFromDecl(p, decl) @@ -2619,8 +2617,7 @@ func (b *Builder) buildDecl(pkg *Package, decl ast.Decl) { if isBlankIdent(id) { continue } - obj := pkg.ObjectOf(id).(*types.TypeName) - nt := obj.Type().(*types.Named) + nt := pkg.ObjectOf(id).Type().(*types.Named) nt.ForEachMethod(func(m *types.Func) { b.buildFunction(b.Prog.concreteMethods[m]) }) diff --git a/ssa/typeinfo.go b/ssa/typeinfo.go index 153c2fbc8c..a087b56c1c 100644 --- a/ssa/typeinfo.go +++ b/ssa/typeinfo.go @@ -65,12 +65,14 @@ func (info *TypeInfo) IsType(e ast.Expr) bool { switch e := e.(type) { case *ast.SelectorExpr: // pkg.Type if obj := info.isPackageRef(e); obj != nil { - return objKind(obj) == ast.Typ + _, isType := obj.(*types.TypeName) + return isType } case *ast.StarExpr: // *T return info.IsType(e.X) case *ast.Ident: - return objKind(info.ObjectOf(e)) == ast.Typ + _, isType := info.ObjectOf(e).(*types.TypeName) + return isType case *ast.ArrayType, *ast.StructType, *ast.FuncType, *ast.InterfaceType, *ast.MapType, *ast.ChanType: return true case *ast.ParenExpr: @@ -86,8 +88,8 @@ func (info *TypeInfo) IsType(e ast.Expr) bool { // func (info *TypeInfo) isPackageRef(sel *ast.SelectorExpr) types.Object { if id, ok := sel.X.(*ast.Ident); ok { - if obj := info.ObjectOf(id); objKind(obj) == ast.Pkg { - return obj.(*types.Package).Scope().Lookup(sel.Sel.Name) + if pkg, ok := info.ObjectOf(id).(*types.Package); ok { + return pkg.Scope().Lookup(sel.Sel.Name) } } return nil diff --git a/ssa/util.go b/ssa/util.go index 398363d795..f16f6ff129 100644 --- a/ssa/util.go +++ b/ssa/util.go @@ -101,23 +101,6 @@ outer: return true } -// objKind returns the syntactic category of the named entity denoted by obj. -func objKind(obj types.Object) ast.ObjKind { - switch obj.(type) { - case *types.Package: - return ast.Pkg - case *types.TypeName: - return ast.Typ - case *types.Const: - return ast.Con - case *types.Var: - return ast.Var - case *types.Func: - return ast.Fun - } - panic(fmt.Sprintf("unexpected Object type: %T", obj)) -} - // canHaveConcreteMethods returns true iff typ may have concrete // methods associated with it. Callers must supply allowPtr=true. //