cmd/vet: remove dependency on types.New
In preparation for removal of types.New. Change-Id: Ieff0c41cf03351124cea32e9b96075a4801c051f Reviewed-on: https://go-review.googlesource.com/10775 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
de24c4870a
commit
f0b0213b21
|
@ -18,15 +18,19 @@ import (
|
||||||
var imports = make(map[string]*types.Package)
|
var imports = make(map[string]*types.Package)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stringerMethodType = types.New("func() string")
|
errorType *types.Interface
|
||||||
errorType = types.New("error").Underlying().(*types.Interface)
|
stringerType *types.Interface
|
||||||
stringerType = types.New("interface{ String() string }").(*types.Interface)
|
formatterType *types.Interface
|
||||||
formatterType *types.Interface
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
typ := importType("fmt", "Formatter")
|
errorType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface)
|
||||||
if typ != nil {
|
|
||||||
|
if typ := importType("fmt", "Stringer"); typ != nil {
|
||||||
|
stringerType = typ.Underlying().(*types.Interface)
|
||||||
|
}
|
||||||
|
|
||||||
|
if typ := importType("fmt", "Formatter"); typ != nil {
|
||||||
formatterType = typ.Underlying().(*types.Interface)
|
formatterType = typ.Underlying().(*types.Interface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,8 +317,9 @@ func (f *File) numArgsInSignature(call *ast.CallExpr) int {
|
||||||
func (f *File) isErrorMethodCall(call *ast.CallExpr) bool {
|
func (f *File) isErrorMethodCall(call *ast.CallExpr) bool {
|
||||||
typ := f.pkg.types[call].Type
|
typ := f.pkg.types[call].Type
|
||||||
if typ != nil {
|
if typ != nil {
|
||||||
// We know it's called "Error", so just check the function signature.
|
// We know it's called "Error", so just check the function signature
|
||||||
return types.Identical(f.pkg.types[call.Fun].Type, stringerMethodType)
|
// (stringerType has exactly one method, String).
|
||||||
|
return types.Identical(f.pkg.types[call.Fun].Type, stringerType.Method(0).Type())
|
||||||
}
|
}
|
||||||
// Without types, we can still check by hand.
|
// Without types, we can still check by hand.
|
||||||
// Is it a selector expression? Otherwise it's a function call, not a method call.
|
// Is it a selector expression? Otherwise it's a function call, not a method call.
|
||||||
|
|
Loading…
Reference in New Issue