mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07:00
cmd/vet: don't panic if import fails
Initializing the unused variable formatterType (it will be used soon) was panicking if the import couldn't be done, but vet shouldn't be so fragile. LGTM=gri R=gri CC=dsymonds, golang-codereviews https://golang.org/cl/153480044
This commit is contained in:
parent
b45b275b99
commit
9be0b38f5b
@ -20,10 +20,17 @@ var imports = make(map[string]*types.Package)
|
||||
var (
|
||||
stringerMethodType = types.New("func() string")
|
||||
errorType = types.New("error").Underlying().(*types.Interface)
|
||||
stringerType = importType("fmt", "Stringer").Underlying().(*types.Interface)
|
||||
formatterType = importType("fmt", "Formatter").Underlying().(*types.Interface)
|
||||
stringerType = types.New("interface{ String() string }").(*types.Interface)
|
||||
formatterType *types.Interface
|
||||
)
|
||||
|
||||
func init() {
|
||||
typ := importType("fmt", "Formatter")
|
||||
if typ != nil {
|
||||
formatterType = typ.Underlying().(*types.Interface)
|
||||
}
|
||||
}
|
||||
|
||||
// importType returns the type denoted by the qualified identifier
|
||||
// path.name, and adds the respective package to the imports map
|
||||
// as a side effect.
|
||||
|
Loading…
Reference in New Issue
Block a user