Also, remove named return values for exprList, genericExprList.
Change-Id: I099abff4572530dd0c3b39c92d6b9a4662d95c2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/493557
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
// exprList evaluates a list of expressions and returns the corresponding operands.
// A single-element expression list may evaluate to multiple operands.
-func (check *Checker) exprList(elist []syntax.Expr) (xlist []*operand) {
+func (check *Checker) exprList(elist []syntax.Expr) []*operand {
switch len(elist) {
case 0:
- // nothing to do
+ return nil
+
case 1:
- xlist, _ = check.multiExpr(elist[0], false)
+ xlist, _ := check.multiExpr(elist[0], false)
+ return xlist
+
default:
// multiple (possibly invalid) values
- xlist = make([]*operand, len(elist))
+ xlist := make([]*operand, len(elist))
for i, e := range elist {
var x operand
check.expr(nil, &x, e)
xlist[i] = &x
}
+ return xlist
}
- return
}
// genericExprList is like exprList but result operands may be generic (not fully instantiated).
-func (check *Checker) genericExprList(elist []syntax.Expr) (xlist []*operand) {
+func (check *Checker) genericExprList(elist []syntax.Expr) []*operand {
switch len(elist) {
case 0:
- // nothing to do
+ return nil
+
case 1:
- xlist = check.genericMultiExpr(elist[0])
+ e := elist[0]
+ var x operand
+ check.rawExpr(nil, &x, e, nil, true)
+ check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
+
+ if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
+ // multiple values - cannot be generic
+ xlist := make([]*operand, t.Len())
+ for i, v := range t.vars {
+ xlist[i] = &operand{mode: value, expr: e, typ: v.typ}
+ }
+ return xlist
+ }
+
+ // exactly one (possible invalid or generic) value
+ return []*operand{&x}
+
default:
// multiple (possibly invalid) values
- xlist = make([]*operand, len(elist))
+ xlist := make([]*operand, len(elist))
for i, e := range elist {
var x operand
check.genericExpr(&x, e)
xlist[i] = &x
}
+ return xlist
}
- return
}
// xlist is the list of type argument expressions supplied in the source code.
return
}
-// genericMultiExpr is like multiExpr but a one-element result may also be generic
-// and potential comma-ok expressions are returned as single values.
-func (check *Checker) genericMultiExpr(e syntax.Expr) (list []*operand) {
- var x operand
- check.rawExpr(nil, &x, e, nil, true)
- check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-
- if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
- // multiple values - cannot be generic
- list = make([]*operand, t.Len())
- for i, v := range t.vars {
- list[i] = &operand{mode: value, expr: e, typ: v.typ}
- }
- return
- }
-
- // exactly one (possible invalid or generic) value
- list = []*operand{&x}
- return
-}
-
// exprWithHint typechecks expression e and initializes x with the expression value;
// hint is the type of a composite literal element.
// If an error occurred, x.mode is set to invalid.
// exprList evaluates a list of expressions and returns the corresponding operands.
// A single-element expression list may evaluate to multiple operands.
-func (check *Checker) exprList(elist []ast.Expr) (xlist []*operand) {
+func (check *Checker) exprList(elist []ast.Expr) []*operand {
switch len(elist) {
case 0:
- // nothing to do
+ return nil
+
case 1:
- xlist, _ = check.multiExpr(elist[0], false)
+ xlist, _ := check.multiExpr(elist[0], false)
+ return xlist
+
default:
// multiple (possibly invalid) values
- xlist = make([]*operand, len(elist))
+ xlist := make([]*operand, len(elist))
for i, e := range elist {
var x operand
check.expr(nil, &x, e)
xlist[i] = &x
}
+ return xlist
}
- return
}
// genericExprList is like exprList but result operands may be generic (not fully instantiated).
-func (check *Checker) genericExprList(elist []ast.Expr) (xlist []*operand) {
+func (check *Checker) genericExprList(elist []ast.Expr) []*operand {
switch len(elist) {
case 0:
- // nothing to do
+ return nil
+
case 1:
- xlist = check.genericMultiExpr(elist[0])
+ e := elist[0]
+ var x operand
+ check.rawExpr(nil, &x, e, nil, true)
+ check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
+
+ if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
+ // multiple values - cannot be generic
+ xlist := make([]*operand, t.Len())
+ for i, v := range t.vars {
+ xlist[i] = &operand{mode: value, expr: e, typ: v.typ}
+ }
+ return xlist
+ }
+
+ // exactly one (possible invalid or generic) value
+ return []*operand{&x}
+
default:
// multiple (possibly invalid) values
- xlist = make([]*operand, len(elist))
+ xlist := make([]*operand, len(elist))
for i, e := range elist {
var x operand
check.genericExpr(&x, e)
xlist[i] = &x
}
+ return xlist
}
- return
}
// xlist is the list of type argument expressions supplied in the source code.
return
}
-// genericMultiExpr is like multiExpr but a one-element result may also be generic
-// and potential comma-ok expressions are returned as single values.
-func (check *Checker) genericMultiExpr(e ast.Expr) (list []*operand) {
- var x operand
- check.rawExpr(nil, &x, e, nil, true)
- check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
-
- if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
- // multiple values - cannot be generic
- list = make([]*operand, t.Len())
- for i, v := range t.vars {
- list[i] = &operand{mode: value, expr: e, typ: v.typ}
- }
- return
- }
-
- // exactly one (possible invalid or generic) value
- list = []*operand{&x}
- return
-}
-
// exprWithHint typechecks expression e and initializes x with the expression value;
// hint is the type of a composite literal element.
// If an error occurred, x.mode is set to invalid.