mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
87e2b34f7b
commit
00b773a4a9
7 changed files with 67 additions and 113 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue