1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:46:47 -07:00

cmd/compile/internal/syntax: minor cleanups in extractName

Backport the recommended changes suggested in CL 403937.

Change-Id: I3ac29c90977e33899881838825da033627344ed2
Reviewed-on: https://go-review.googlesource.com/c/go/+/403853
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-05-04 11:56:10 -07:00
parent ab0bb52f2f
commit fbb47e81c1

View File

@ -683,14 +683,14 @@ func extractName(x Expr, force bool) (*Name, Expr) {
}
switch x.Op {
case Mul:
if name, _ := x.X.(*Name); name != nil && (isTypeElem(x.Y) || force) {
if name, _ := x.X.(*Name); name != nil && (force || isTypeElem(x.Y)) {
// x = name *x.Y
op := *x
op.X, op.Y = op.Y, nil // change op into unary *op.Y
return name, &op
}
case Or:
if name, lhs := extractName(x.X, isTypeElem(x.Y) || force); name != nil && lhs != nil { // note: lhs should never be nil
if name, lhs := extractName(x.X, force || isTypeElem(x.Y)); name != nil && lhs != nil {
// x = name lhs|x.Y
op := *x
op.X = lhs
@ -699,7 +699,7 @@ func extractName(x Expr, force bool) (*Name, Expr) {
}
case *CallExpr:
if name, _ := x.Fun.(*Name); name != nil {
if len(x.ArgList) == 1 && !x.HasDots && (isTypeElem(x.ArgList[0]) || force) {
if len(x.ArgList) == 1 && !x.HasDots && (force || isTypeElem(x.ArgList[0])) {
// x = name "(" x.ArgList[0] ")"
return name, x.ArgList[0]
}