[dev.typeparams] cmd/compile: fix escape printout bugs for -G=3

Call SetPos() in g.expr() so it is available for any new nodes.

Print out the actual type for a composite literal in exprFmt() if
available, else use Ntype if available. Seems generally useful, since
the type name is always more useful than just 'composite literal'.

Fixes a bunch of cases that are excluded in run.go for -G=3.

Change-Id: I40b9bba88027ea4f36d419e3989e7f14891bea04
Reviewed-on: https://go-review.googlesource.com/c/go/+/334609
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Dan Scales 2021-07-13 22:21:54 -07:00
parent 2b10d7ff0b
commit e3e6cd3022
3 changed files with 12 additions and 31 deletions

View file

@ -88,6 +88,11 @@ func (g *irgen) expr(expr syntax.Expr) ir.Node {
func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
pos := g.pos(expr)
assert(pos.IsKnown())
// Set base.Pos for transformation code that still uses base.Pos, rather than
// the pos of the node being converted.
base.Pos = pos
switch expr := expr.(type) {
case *syntax.Name: