Commit d73452b3 authored by Rob Pike's avatar Rob Pike

cmd/vet: fix for changes to go/types package

Need to use (or stub) exact.Value.

R=gri
CC=golang-dev
https://golang.org/cl/9126043
parent d535bc7a
...@@ -179,7 +179,7 @@ func doPackageDir(directory string) { ...@@ -179,7 +179,7 @@ func doPackageDir(directory string) {
type Package struct { type Package struct {
types map[ast.Expr]Type types map[ast.Expr]Type
values map[ast.Expr]interface{} values map[ast.Expr]ExactValue
files []*File files []*File
} }
......
...@@ -14,19 +14,27 @@ import ( ...@@ -14,19 +14,27 @@ import (
"go/ast" "go/ast"
"go/token" "go/token"
"code.google.com/p/go.exp/go/exact"
"code.google.com/p/go.exp/go/types" "code.google.com/p/go.exp/go/types"
) )
// Type is equivalent to go/types.Type. Repeating it here allows us to avoid // Type is equivalent to types.Type. Repeating it here allows us to avoid
// depending on the go/types package. // having main depend on the go/types package.
type Type interface { type Type interface {
String() string String() string
} }
// ExactValue is equivalent to exact.Value. Repeating it here allows us to
// avoid having main depend on the go/exact package.
type ExactValue interface {
Kind() exact.Kind
String() string
}
func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error { func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
pkg.types = make(map[ast.Expr]Type) pkg.types = make(map[ast.Expr]Type)
pkg.values = make(map[ast.Expr]interface{}) pkg.values = make(map[ast.Expr]ExactValue)
exprFn := func(x ast.Expr, typ types.Type, val interface{}) { exprFn := func(x ast.Expr, typ types.Type, val exact.Value) {
pkg.types[x] = typ pkg.types[x] = typ
if val != nil { if val != nil {
pkg.values[x] = val pkg.values[x] = val
...@@ -93,10 +101,8 @@ func (f *File) matchArgType(t printfArgType, arg ast.Expr) bool { ...@@ -93,10 +101,8 @@ func (f *File) matchArgType(t printfArgType, arg ast.Expr) bool {
return t&argFloat != 0 return t&argFloat != 0
case types.UntypedFloat: case types.UntypedFloat:
// If it's integral, we can use an int format. // If it's integral, we can use an int format.
switch f.pkg.values[arg].(type) { switch f.pkg.values[arg].Kind() {
case int, int8, int16, int32, int64: case exact.Int:
return t&(argInt|argFloat) != 0
case uint, uint8, uint16, uint32, uint64:
return t&(argInt|argFloat) != 0 return t&(argInt|argFloat) != 0
} }
return t&argFloat != 0 return t&argFloat != 0
......
...@@ -15,11 +15,16 @@ import ( ...@@ -15,11 +15,16 @@ import (
) )
// Type is equivalent to go/types.Type. Repeating it here allows us to avoid // Type is equivalent to go/types.Type. Repeating it here allows us to avoid
// depending on the go/types package. // having main depend on the go/types package.
type Type interface { type Type interface {
String() string String() string
} }
// ExactValue is a stub for exact.Value. Stubbing it here allows us to
// avoid having main depend on the go/exact package.
type ExactValue interface {
}
func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error { func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
return nil return nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment