From efe9ad501d94743d87e500a7ba0b1732a89e9afd Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 25 Nov 2025 16:26:25 -0800 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Freeman Auto-Submit: Robert Griesemer --- src/cmd/compile/internal/types2/format.go | 11 +++++++++++ src/go/types/format.go | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cmd/compile/internal/types2/format.go b/src/cmd/compile/internal/types2/format.go index b61dfda1c81..d7aa2399c7b 100644 --- a/src/cmd/compile/internal/types2/format.go +++ b/src/cmd/compile/internal/types2/format.go @@ -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: diff --git a/src/go/types/format.go b/src/go/types/format.go index 550d22f5aeb..8df72f98e6f 100644 --- a/src/go/types/format.go +++ b/src/go/types/format.go @@ -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()