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:
Robert Griesemer 2025-11-25 16:26:25 -08:00 committed by Gopher Robot
parent ac3369242d
commit efe9ad501d
2 changed files with 22 additions and 0 deletions

View file

@ -23,6 +23,17 @@ func sprintf(qf Qualifier, tpSubscripts bool, format string, args ...any) string
panic("got operand instead of *operand")
case *operand:
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:
arg = a.String()
case syntax.Expr:

View file

@ -24,6 +24,17 @@ func sprintf(fset *token.FileSet, qf Qualifier, tpSubscripts bool, format string
panic("got operand instead of *operand")
case *operand:
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:
if fset != nil {
arg = fset.Position(a).String()