]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: use ExprString instead of syntax.String
authorRobert Griesemer <gri@golang.org>
Thu, 8 Feb 2024 23:35:22 +0000 (15:35 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 20 Feb 2024 18:06:31 +0000 (18:06 +0000)
This further reduces the differences between go/types and types2.

Change-Id: I1426c2f7c58e2d1123d93f68fbdda01b0cc2d46e
Reviewed-on: https://go-review.googlesource.com/c/go/+/562836
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/builtins_test.go
src/cmd/compile/internal/types2/errors.go
src/cmd/compile/internal/types2/issues_test.go
src/cmd/compile/internal/types2/operand.go
src/cmd/compile/internal/types2/util.go

index bacba719553b34c079467ac99341f4954ca7d2f2..bab120ff9335d13a68e83ab4ef4304757147ccdf 100644 (file)
@@ -152,7 +152,7 @@ func TestValuesInfo(t *testing.T) {
                // look for expression
                var expr syntax.Expr
                for e := range info.Types {
-                       if syntax.String(e) == test.expr {
+                       if ExprString(e) == test.expr {
                                expr = e
                                break
                        }
@@ -424,7 +424,7 @@ func TestTypesInfo(t *testing.T) {
                // look for expression type
                var typ Type
                for e, tv := range info.Types {
-                       if syntax.String(e) == test.expr {
+                       if ExprString(e) == test.expr {
                                typ = tv.Type
                                break
                        }
@@ -1135,8 +1135,8 @@ func TestPredicatesInfo(t *testing.T) {
                // look for expression predicates
                got := "<missing>"
                for e, tv := range info.Types {
-                       //println(name, syntax.String(e))
-                       if syntax.String(e) == test.expr {
+                       //println(name, ExprString(e))
+                       if ExprString(e) == test.expr {
                                got = predString(tv)
                                break
                        }
index 8abafdba1bac038968248244b68140392efe631e..612c6ca97216071ca3c1c2edb96b6bfdb01ed810 100644 (file)
@@ -218,7 +218,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
                        var op operand
                        check.expr(nil, &op, sel.X)
                        if op.mode == mapindex {
-                               check.errorf(&x, UnaddressableFieldAssign, "cannot assign to struct field %s in map", syntax.String(x.expr))
+                               check.errorf(&x, UnaddressableFieldAssign, "cannot assign to struct field %s in map", ExprString(x.expr))
                                return Typ[Invalid]
                        }
                }
@@ -248,7 +248,7 @@ func (check *Checker) assignVar(lhs, rhs syntax.Expr, x *operand, context string
                // avoid calling syntax.String if not needed
                if T != nil {
                        if _, ok := under(T).(*Signature); ok {
-                               target = newTarget(T, syntax.String(lhs))
+                               target = newTarget(T, ExprString(lhs))
                        }
                }
                x = new(operand)
index 875ee5a4d5dde41245e1f8673cb9a8602765b66d..2b4854b6f7ec0b1d1b8c24fff8803bce1fb85071 100644 (file)
@@ -207,7 +207,7 @@ func testBuiltinSignature(t *testing.T, name, src0, want string) {
                // the recorded type for the built-in must match the wanted signature
                typ := types[fun].Type
                if typ == nil {
-                       t.Errorf("%s: no type recorded for %s", src0, syntax.String(fun))
+                       t.Errorf("%s: no type recorded for %s", src0, ExprString(fun))
                        return
                }
                if got := typ.String(); got != want {
index b8414b48498f242b088f5f8d1517156de31db1e4..4326ca67ef9d8ab8c29959f52d56217d662e8671 100644 (file)
@@ -102,7 +102,7 @@ func sprintf(qf Qualifier, tpSubscripts bool, format string, args ...interface{}
                case syntax.Pos:
                        arg = a.String()
                case syntax.Expr:
-                       arg = syntax.String(a)
+                       arg = ExprString(a)
                case []syntax.Expr:
                        var buf strings.Builder
                        buf.WriteByte('[')
@@ -110,7 +110,7 @@ func sprintf(qf Qualifier, tpSubscripts bool, format string, args ...interface{}
                                if i > 0 {
                                        buf.WriteString(", ")
                                }
-                               buf.WriteString(syntax.String(x))
+                               buf.WriteString(ExprString(x))
                        }
                        buf.WriteByte(']')
                        arg = buf.String()
index 0117571f7b043c3f027626d663079743be92f82f..0275fe70d7148f8f882b8e6a3ed7301e72c65eab 100644 (file)
@@ -698,14 +698,14 @@ func TestIssue51093(t *testing.T) {
                                n++
                                tpar, _ := tv.Type.(*TypeParam)
                                if tpar == nil {
-                                       t.Fatalf("%s: got type %s, want type parameter", syntax.String(x), tv.Type)
+                                       t.Fatalf("%s: got type %s, want type parameter", ExprString(x), tv.Type)
                                }
                                if name := tpar.Obj().Name(); name != "P" {
-                                       t.Fatalf("%s: got type parameter name %s, want P", syntax.String(x), name)
+                                       t.Fatalf("%s: got type parameter name %s, want P", ExprString(x), name)
                                }
                                // P(val) must not be constant
                                if tv.Value != nil {
-                                       t.Errorf("%s: got constant value %s (%s), want no constant", syntax.String(x), tv.Value, tv.Value.String())
+                                       t.Errorf("%s: got constant value %s (%s), want no constant", ExprString(x), tv.Value, tv.Value.String())
                                }
                        }
                }
index 3f151007e577beb4b8df409c7114b0f3b4d55438..236ce412605bbfe65fa1441b2b0da0c7b0e4be05 100644 (file)
@@ -124,7 +124,7 @@ func operandString(x *operand, qf Qualifier) string {
 
        var expr string
        if x.expr != nil {
-               expr = syntax.String(x.expr)
+               expr = ExprString(x.expr)
        } else {
                switch x.mode {
                case builtin:
index d77da478fac1cf9dde00b32e9dac801b719dca46..35ab71be2b0db543e887842ccec4899e8eb54d84 100644 (file)
@@ -23,3 +23,6 @@ func cmpPos(p, q syntax.Pos) int { return p.Cmp(q) }
 
 // hasDots reports whether the last argument in the call is followed by ...
 func hasDots(call *syntax.CallExpr) bool { return call.HasDots }
+
+// ExprString returns a string representation of x.
+func ExprString(x syntax.Node) string { return syntax.String(x) }