Skip to content

Commit

Permalink
cmd/compile/internal/syntax: minor cleanups in extractName
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
griesemer committed May 4, 2022
1 parent ab0bb52 commit fbb47e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
}
Expand Down

0 comments on commit fbb47e8

Please sign in to comment.