aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2022-01-11 22:19:56 -0800
committerRobert Griesemer <gri@golang.org>2022-01-12 19:03:12 +0000
commita4b6fc7b1ddcec937b605b76068f8e800c1487e2 (patch)
tree1eebb53e207ee3c203b8f6849fae043f48f63353 /src/go
parentdeb45802a4384ea3c7c3434113fb64a57a494cb2 (diff)
downloadgo-a4b6fc7b1ddcec937b605b76068f8e800c1487e2.tar.gz
go-a4b6fc7b1ddcec937b605b76068f8e800c1487e2.zip
go/types, types2: fix tracing output for type and expr lists
- support printing of expression and type lists in sprintf - simplified some code in go/types/exprstring.go - fixed a typo in syntax package Change-Id: Ic4bc154200aad95958d5bc2904a9ea17cf518388 Reviewed-on: https://go-review.googlesource.com/c/go/+/377974 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/errors.go18
-rw-r--r--src/go/types/exprstring.go7
2 files changed, 19 insertions, 6 deletions
diff --git a/src/go/types/errors.go b/src/go/types/errors.go
index 81c62a82f0..ce62a8cbdd 100644
--- a/src/go/types/errors.go
+++ b/src/go/types/errors.go
@@ -7,6 +7,7 @@
package types
import (
+ "bytes"
"errors"
"fmt"
"go/ast"
@@ -81,10 +82,27 @@ func sprintf(fset *token.FileSet, qf Qualifier, debug bool, format string, args
}
case ast.Expr:
arg = ExprString(a)
+ case []ast.Expr:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ writeExprList(&buf, a)
+ buf.WriteByte(']')
+ arg = buf.String()
case Object:
arg = ObjectString(a, qf)
case Type:
arg = typeString(a, qf, debug)
+ case []Type:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ for i, x := range a {
+ if i > 0 {
+ buf.WriteString(", ")
+ }
+ buf.WriteString(typeString(x, qf, debug))
+ }
+ buf.WriteByte(']')
+ arg = buf.String()
}
args[i] = arg
}
diff --git a/src/go/types/exprstring.go b/src/go/types/exprstring.go
index aa4f403c1f..544cd84d61 100644
--- a/src/go/types/exprstring.go
+++ b/src/go/types/exprstring.go
@@ -71,12 +71,7 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
ix := typeparams.UnpackIndexExpr(x)
WriteExpr(buf, ix.X)
buf.WriteByte('[')
- for i, e := range ix.Indices {
- if i > 0 {
- buf.WriteString(", ")
- }
- WriteExpr(buf, e)
- }
+ writeExprList(buf, ix.Indices)
buf.WriteByte(']')
case *ast.SliceExpr: