cmd/compile: simplify OPTRLIT handling

Previously, we would recognize &(T{...}) expressions during type
checking, rewrite them into (*T){...}, and then do a lot of extra work
to make sure the user doesn't write (*T){...} themselves and
resynthesizing the OPTRLIT later on.

This CL simply handles &T{...} directly in the straight forward
manner, by changing OADDR directly to OPTRLIT when appropriate.

While here, match go/types's invalid composite literal type error
message.

Passes toolstash-check.

Change-Id: I902b14c7e2cd9fa93e6915dd58272d2352ba38f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/197120
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2019-09-25 00:21:23 -07:00
parent 87e2b34f7b
commit 00b773a4a9
7 changed files with 67 additions and 113 deletions

View file

@ -662,15 +662,6 @@ func (p *noder) expr(expr syntax.Expr) *Node {
}
x := p.expr(expr.X)
if expr.Y == nil {
if expr.Op == syntax.And {
x = unparen(x) // TODO(mdempsky): Needed?
if x.Op == OCOMPLIT {
// Special case for &T{...}: turn into (*T){...}.
x.Right = p.nod(expr, ODEREF, x.Right, nil)
x.Right.SetImplicit(true)
return x
}
}
return p.nod(expr, p.unOp(expr.Op), x, nil)
}
return p.nod(expr, p.binOp(expr.Op), x, p.expr(expr.Y))