]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: improve printing of []*operand lists (debugging support)
authorRobert Griesemer <gri@google.com>
Wed, 26 Nov 2025 00:26:25 +0000 (16:26 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 26 Nov 2025 20:38:54 +0000 (12:38 -0800)
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>

src/cmd/compile/internal/types2/format.go
src/go/types/format.go

index b61dfda1c819f63f3c2b8c51fc980edf1d370bc7..d7aa2399c7b8fa0b392021964de4b073832e8e28 100644 (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:
index 550d22f5aeb791f101847adbfe97b3de2ed5b57a..8df72f98e6fa8ef2eb254a4b8c3486475a409bee 100644 (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()