diff options
Diffstat (limited to 'libgo/go/fmt/print.go')
-rw-r--r-- | libgo/go/fmt/print.go | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go index e5ca117..8b15a82 100644 --- a/libgo/go/fmt/print.go +++ b/libgo/go/fmt/print.go @@ -631,24 +631,30 @@ func (p *pp) handleMethods(verb rune, plus, goSyntax bool, depth int) (wasString return } } else { - // Is it an error or Stringer? - // The duplication in the bodies is necessary: - // setting wasString and handled and deferring catchPanic - // must happen before calling the method. - switch v := p.field.(type) { - case error: - wasString = false - handled = true - defer p.catchPanic(p.field, verb) - p.printField(v.Error(), verb, plus, false, depth) - return - - case Stringer: - wasString = false - handled = true - defer p.catchPanic(p.field, verb) - p.printField(v.String(), verb, plus, false, depth) - return + // If a string is acceptable according to the format, see if + // the value satisfies one of the string-valued interfaces. + // Println etc. set verb to %v, which is "stringable". + switch verb { + case 'v', 's', 'x', 'X', 'q': + // Is it an error or Stringer? + // The duplication in the bodies is necessary: + // setting wasString and handled, and deferring catchPanic, + // must happen before calling the method. + switch v := p.field.(type) { + case error: + wasString = false + handled = true + defer p.catchPanic(p.field, verb) + p.printField(v.Error(), verb, plus, false, depth) + return + + case Stringer: + wasString = false + handled = true + defer p.catchPanic(p.field, verb) + p.printField(v.String(), verb, plus, false, depth) + return + } } } handled = false |