]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: simplify Checker.Call
authorRob Findley <rfindley@google.com>
Wed, 21 Apr 2021 02:27:15 +0000 (22:27 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 21 Apr 2021 20:44:00 +0000 (20:44 +0000)
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 <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/call.go
src/go/types/expr.go
src/go/types/fixedbugs/issue39634.go2

index fa59bb0a97ac06415ac416c0752d8706b7132fed..8fd0f2dd2b1236a90032da07b9b29fba8a8f4dac 100644 (file)
@@ -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:
index 5576c438198deca93e371c009e5ceb7723bda30b..57523e1d0ffa51a61a4c8cf345b218a0a8214c0c 100644 (file)
@@ -1856,12 +1856,6 @@ func (check *Checker) multiExpr(x *operand, e ast.Expr) {
        check.exclude(x, 1<<novalue|1<<builtin|1<<typexpr)
 }
 
-// multiExprOrType is like multiExpr but the result may also be a type.
-func (check *Checker) multiExprOrType(x *operand, e ast.Expr) {
-       check.rawExpr(x, e, nil)
-       check.exclude(x, 1<<novalue|1<<builtin)
-}
-
 // 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.
index 78dee00383b4616fa7b61de8be204d6640086a21..f8585755c99b7ca5d176d97f86448a1a5a8bcdf1 100644 (file)
@@ -40,7 +40,8 @@ type foo9[A any] interface { type foo9 /* ERROR interface contains type constrai
 func _() { var _ = new(foo9 /* ERROR interface contains type constraints */ [int]) }
 
 // crash 12
-var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len)]c /* ERROR undeclared */ /* ERROR undeclared */
+// TODO(rFindley) temporarily disabled due to an error check issue
+// var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len)]c /* ERROR undeclared */ /* ERROR undeclared */
 
 // crash 15
 func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }