diff options
Diffstat (limited to 'libgo/go/cmd/vet/types.go')
-rw-r--r-- | libgo/go/cmd/vet/types.go | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/libgo/go/cmd/vet/types.go b/libgo/go/cmd/vet/types.go index d83611b4da0..5f8e481e01b 100644 --- a/libgo/go/cmd/vet/types.go +++ b/libgo/go/cmd/vet/types.go @@ -12,7 +12,6 @@ import ( "go/importer" "go/token" "go/types" - "runtime" ) // stdImporter is the importer we use to import packages. @@ -173,7 +172,7 @@ func (f *File) matchArgTypeInternal(t printfArgType, typ types.Type, arg ast.Exp return true // %s matches []byte } // Recur: []int matches %d. - return t&argPointer != 0 || f.matchArgTypeInternal(t, typ.Elem().Underlying(), arg, inProgress) + return t&argPointer != 0 || f.matchArgTypeInternal(t, typ.Elem(), arg, inProgress) case *types.Slice: // Same as array. @@ -202,8 +201,8 @@ func (f *File) matchArgTypeInternal(t printfArgType, typ types.Type, arg ast.Exp if str, ok := typ.Elem().Underlying().(*types.Struct); ok { return f.matchStructArgType(t, str, arg, inProgress) } - // The rest can print with %p as pointers, or as integers with %x etc. - return t&(argInt|argPointer) != 0 + // Check whether the rest can print pointers. + return t&argPointer != 0 case *types.Struct: return f.matchStructArgType(t, typ, arg, inProgress) @@ -255,7 +254,7 @@ func (f *File) matchArgTypeInternal(t printfArgType, typ types.Type, arg ast.Exp return t&(argInt|argRune) != 0 case types.UntypedNil: - return t&argPointer != 0 // TODO? + return false case types.Invalid: if *verbose { @@ -270,7 +269,19 @@ func (f *File) matchArgTypeInternal(t printfArgType, typ types.Type, arg ast.Exp } func isConvertibleToString(typ types.Type) bool { - return types.AssertableTo(errorType, typ) || stringerType != nil && types.AssertableTo(stringerType, typ) + if bt, ok := typ.(*types.Basic); ok && bt.Kind() == types.UntypedNil { + // We explicitly don't want untyped nil, which is + // convertible to both of the interfaces below, as it + // would just panic anyway. + return false + } + if types.ConvertibleTo(typ, errorType) { + return true // via .Error() + } + if stringerType != nil && types.ConvertibleTo(typ, stringerType) { + return true // via .String() + } + return false } // hasBasicType reports whether x's type is a types.Basic with the given kind. @@ -299,15 +310,4 @@ func (f *File) matchStructArgType(t printfArgType, typ *types.Struct, arg ast.Ex return true } -// hasMethod reports whether the type contains a method with the given name. -// It is part of the workaround for Formatters and should be deleted when -// that workaround is no longer necessary. -// TODO: This could be better once issue 6259 is fixed. -func (f *File) hasMethod(typ types.Type, name string) bool { - // assume we have an addressable variable of type typ - obj, _, _ := types.LookupFieldOrMethod(typ, true, f.pkg.typesPkg, name) - _, ok := obj.(*types.Func) - return ok -} - -var archSizes = types.SizesFor(runtime.Compiler, build.Default.GOARCH) +var archSizes = types.SizesFor("gc", build.Default.GOARCH) |