1
0
mirror of https://github.com/golang/go synced 2024-09-29 07:14:29 -06:00

cmd/compile/internal/types2: use ExprString instead of syntax.String

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>
This commit is contained in:
Robert Griesemer 2024-02-08 15:35:22 -08:00 committed by Gopher Robot
parent c1828fbcbf
commit 67361bf868
7 changed files with 16 additions and 13 deletions

View 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
}

View 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)

View 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 {

View 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()

View 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())
}
}
}

View 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:

View 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) }