cmd/vet: check for nil result set in isStringer

Fixes golang/go#7149.

LGTM=gri
R=golang-codereviews, gri
CC=golang-codereviews
https://golang.org/cl/68260044
This commit is contained in:
Rob Pike 2014-02-24 11:39:42 -08:00
parent cde4d316d2
commit ee3eeefaa3
3 changed files with 9 additions and 3 deletions

View File

@ -22,7 +22,7 @@ vets the files named, all of which must be in the same package.
By directory: By directory:
go tool vet source/directory go tool vet source/directory
recursively descends the directory, vetting each file in isolation. recursively descends the directory, vetting each file in isolation.
Package-level type-checking disabled, so the vetting is weaker. Package-level type-checking is disabled, so the vetting is weaker.
Vet's exit code is 2 for erroneous invocation of the tool, 1 if a Vet's exit code is 2 for erroneous invocation of the tool, 1 if a
problem was reported, and 0 otherwise. Note that the tool does not problem was reported, and 0 otherwise. Note that the tool does not

View File

@ -76,7 +76,8 @@ func Usage() {
fmt.Fprintf(os.Stderr, "\tvet [flags] directory...\n") fmt.Fprintf(os.Stderr, "\tvet [flags] directory...\n")
fmt.Fprintf(os.Stderr, "\tvet [flags] files... # Must be a single package\n") fmt.Fprintf(os.Stderr, "\tvet [flags] files... # Must be a single package\n")
fmt.Fprintf(os.Stderr, "For more information run\n") fmt.Fprintf(os.Stderr, "For more information run\n")
fmt.Fprintf(os.Stderr, "\tgodoc code.google.com/p/go.tools/cmd/vet\n\nFlags:\n") fmt.Fprintf(os.Stderr, "\tgodoc code.google.com/p/go.tools/cmd/vet\n\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults() flag.PrintDefaults()
os.Exit(2) os.Exit(2)
} }
@ -457,7 +458,7 @@ func (f *File) prepStringerReceiver(d *ast.FuncDecl) {
// isStringer returns true if the provided declaration is a "String() string" // isStringer returns true if the provided declaration is a "String() string"
// method; an implementation of fmt.Stringer. // method; an implementation of fmt.Stringer.
func (f *File) isStringer(d *ast.FuncDecl) bool { func (f *File) isStringer(d *ast.FuncDecl) bool {
return d.Recv != nil && d.Name.Name == "String" && return d.Recv != nil && d.Name.Name == "String" && d.Type.Results != nil &&
len(d.Type.Params.List) == 0 && len(d.Type.Results.List) == 1 && len(d.Type.Params.List) == 0 && len(d.Type.Results.List) == 1 &&
f.pkg.types[d.Type.Results.List[0].Type].Type == types.Typ[types.String] f.pkg.types[d.Type.Results.List[0].Type].Type == types.Typ[types.String]
} }

View File

@ -323,3 +323,8 @@ type RecursiveStruct2 struct {
} }
var recursiveStruct1V = &RecursiveStruct1{} var recursiveStruct1V = &RecursiveStruct1{}
// Fix for issue 7149: Missing return type on String method caused fault.
func (int) String() {
return ""
}