Skip to content

Commit

Permalink
DebugPrint: Print the string value of tokens
Browse files Browse the repository at this point in the history
In DebugPrint, if a value implements fmt.Stringer, and isn't a zero
value, display its string value in addition to the default %#v format.

For the most part, this prints the string value of "tokens", e.g. for a
syntax.Redirect.Op, instead of "Op: 0x3b", you get "Op: 0x3b (>&)".
  • Loading branch information
theclapp authored and mvdan committed Apr 27, 2024
1 parent 9b91d69 commit a76dc6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion syntax/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ func (p *debugPrinter) print(x reflect.Value) {
}
p.printf("}")
default:
p.printf("%#v", x.Interface())
if s, ok := x.Interface().(fmt.Stringer); ok && !x.IsZero() {
p.printf("%#v (%s)", x.Interface(), s)
} else {
p.printf("%#v", x.Interface())
}
}
}

0 comments on commit a76dc6c

Please sign in to comment.