mirror of
https://github.com/golang/go
synced 2024-11-05 15:46:11 -07:00
go.tools/cmd/vet: relax recursive stringer check
For the pointer receiver x, fmt.Sprintf(*x) does not invoke x's String method. R=golang-dev, r CC=golang-dev https://golang.org/cl/12971045
This commit is contained in:
parent
cec37cabd4
commit
f6a22edf66
@ -402,10 +402,6 @@ func (f *File) recursiveStringer(arg ast.Expr) bool {
|
|||||||
switch e := arg.(type) {
|
switch e := arg.(type) {
|
||||||
case *ast.Ident:
|
case *ast.Ident:
|
||||||
obj = e.Obj
|
obj = e.Obj
|
||||||
case *ast.StarExpr:
|
|
||||||
if id, ok := e.X.(*ast.Ident); ok {
|
|
||||||
obj = id.Obj
|
|
||||||
}
|
|
||||||
case *ast.UnaryExpr:
|
case *ast.UnaryExpr:
|
||||||
if id, ok := e.X.(*ast.Ident); ok && e.Op == token.AND {
|
if id, ok := e.X.(*ast.Ident); ok && e.Op == token.AND {
|
||||||
obj = id.Obj
|
obj = id.Obj
|
||||||
|
2
cmd/vet/testdata/print.go
vendored
2
cmd/vet/testdata/print.go
vendored
@ -282,6 +282,6 @@ func (s recursiveStringer) String() string {
|
|||||||
type recursivePtrStringer int
|
type recursivePtrStringer int
|
||||||
|
|
||||||
func (p *recursivePtrStringer) String() string {
|
func (p *recursivePtrStringer) String() string {
|
||||||
fmt.Sprintf("%v", *p) // ERROR "arg \*p for printf causes recursive call to String method"
|
fmt.Sprintf("%v", *p)
|
||||||
return fmt.Sprintln(p) // ERROR "arg p for print causes recursive call to String method"
|
return fmt.Sprintln(p) // ERROR "arg p for print causes recursive call to String method"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user