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>
// 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
}
// 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
}
// 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
}
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]
}
}
// 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)
// 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 {
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('[')
if i > 0 {
buf.WriteString(", ")
}
- buf.WriteString(syntax.String(x))
+ buf.WriteString(ExprString(x))
}
buf.WriteByte(']')
arg = buf.String()
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())
}
}
}
var expr string
if x.expr != nil {
- expr = syntax.String(x.expr)
+ expr = ExprString(x.expr)
} else {
switch x.mode {
case builtin:
// 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) }