From: Rob Findley Date: Wed, 21 Apr 2021 02:27:15 +0000 (-0400) Subject: go/types: simplify Checker.Call X-Git-Tag: go1.17beta1~518 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=122fca49f9;p=gostls13.git go/types: simplify Checker.Call This is a direct port of CL 306171 to go/types. Change-Id: I6f0102c76bad3f1d939074fc4c59f772dd417498 Reviewed-on: https://go-review.googlesource.com/c/go/+/312190 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/types/call.go b/src/go/types/call.go index fa59bb0a97..8fd0f2dd2b 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -150,13 +150,7 @@ func (check *Checker) call(x *operand, call *ast.CallExpr) exprKind { } // evaluate arguments - args, ok := check.exprOrTypeList(call.Args) - if !ok { - x.mode = invalid - x.expr = call - return expression - } - + args, _ := check.exprList(call.Args, false) sig = check.arguments(call, sig, args) // determine result @@ -187,60 +181,6 @@ func (check *Checker) call(x *operand, call *ast.CallExpr) exprKind { } } -// exprOrTypeList returns a list of operands and reports an error if the -// list contains a mix of values and types (ignoring invalid operands). -// TODO(rFindley) Now we can split this into exprList and typeList. -func (check *Checker) exprOrTypeList(elist []ast.Expr) (xlist []*operand, ok bool) { - ok = true - - switch len(elist) { - case 0: - // nothing to do - - case 1: - // single (possibly comma-ok) value or type, or function returning multiple values - e := elist[0] - var x operand - check.multiExprOrType(&x, e) - if t, ok := x.typ.(*Tuple); ok && x.mode != invalid && x.mode != typexpr { - // multiple values - xlist = make([]*operand, t.Len()) - for i, v := range t.vars { - xlist[i] = &operand{mode: value, expr: e, typ: v.typ} - } - break - } - - check.instantiatedOperand(&x) - - // exactly one (possibly invalid or comma-ok) value or type - xlist = []*operand{&x} - - default: - // multiple (possibly invalid) values or types - xlist = make([]*operand, len(elist)) - ntypes := 0 - for i, e := range elist { - var x operand - check.exprOrType(&x, e) - xlist[i] = &x - switch x.mode { - case invalid: - ntypes = len(xlist) // make 'if' condition fail below (no additional error in this case) - case typexpr: - ntypes++ - check.instantiatedOperand(&x) - } - } - if 0 < ntypes && ntypes < len(xlist) { - check.errorf(xlist[0], 0, "mix of value and type expressions") - ok = false - } - } - - return -} - func (check *Checker) exprList(elist []ast.Expr, allowCommaOk bool) (xlist []*operand, commaOk bool) { switch len(elist) { case 0: diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 5576c43819..57523e1d0f 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1856,12 +1856,6 @@ func (check *Checker) multiExpr(x *operand, e ast.Expr) { check.exclude(x, 1<