mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
go/types, types2: improve printing of []*operand lists (debugging support)
Special-case an sprintf argument of []*operand type, similar to what we do for other lists. As a result a list of operands is printed as [a, b, c] rather than [a b c] (default formatting for slices). (We could factor out this code into a generic function, but this is a minimally intrusive change at this point.) Change-Id: Iea4fc6ea375dd9618316b7317a77b57b4e35544d Reviewed-on: https://go-review.googlesource.com/c/go/+/724500 Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
ac3369242d
commit
efe9ad501d
2 changed files with 22 additions and 0 deletions
|
|
@ -23,6 +23,17 @@ func sprintf(qf Qualifier, tpSubscripts bool, format string, args ...any) string
|
||||||
panic("got operand instead of *operand")
|
panic("got operand instead of *operand")
|
||||||
case *operand:
|
case *operand:
|
||||||
arg = operandString(a, qf)
|
arg = operandString(a, qf)
|
||||||
|
case []*operand:
|
||||||
|
var buf strings.Builder
|
||||||
|
buf.WriteByte('[')
|
||||||
|
for i, x := range a {
|
||||||
|
if i > 0 {
|
||||||
|
buf.WriteString(", ")
|
||||||
|
}
|
||||||
|
buf.WriteString(operandString(x, qf))
|
||||||
|
}
|
||||||
|
buf.WriteByte(']')
|
||||||
|
arg = buf.String()
|
||||||
case syntax.Pos:
|
case syntax.Pos:
|
||||||
arg = a.String()
|
arg = a.String()
|
||||||
case syntax.Expr:
|
case syntax.Expr:
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,17 @@ func sprintf(fset *token.FileSet, qf Qualifier, tpSubscripts bool, format string
|
||||||
panic("got operand instead of *operand")
|
panic("got operand instead of *operand")
|
||||||
case *operand:
|
case *operand:
|
||||||
arg = operandString(a, qf)
|
arg = operandString(a, qf)
|
||||||
|
case []*operand:
|
||||||
|
var buf strings.Builder
|
||||||
|
buf.WriteByte('[')
|
||||||
|
for i, x := range a {
|
||||||
|
if i > 0 {
|
||||||
|
buf.WriteString(", ")
|
||||||
|
}
|
||||||
|
buf.WriteString(operandString(x, qf))
|
||||||
|
}
|
||||||
|
buf.WriteByte(']')
|
||||||
|
arg = buf.String()
|
||||||
case token.Pos:
|
case token.Pos:
|
||||||
if fset != nil {
|
if fset != nil {
|
||||||
arg = fset.Position(a).String()
|
arg = fset.Position(a).String()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue