]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove superfluous argument test in Checker.arguments
authorRobert Griesemer <gri@golang.org>
Tue, 16 May 2023 18:34:14 +0000 (11:34 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 16 May 2023 22:41:49 +0000 (22:41 +0000)
There's only two places which call Checker.arguments: Checker.callExpr
and Checker.builtin. Both ensure that the passed argument list doesn't
contain type expressions, so we don't need that extra check at the start
of Checker.arguments.

The remaining check causes Checker.arguments to exit early if any of
the passed arguments is invalid. This reduces the number of reported
errors in rare cases but is executed all the time.
If the extra errors are a problem, it would be better to not call
Checker.arguments in the first place, or only do the extra check
before Checker.arguments reports an error.

Removing this code for now. Removes a long-standing TODO.

Change-Id: Ief654b680eb6b6a768bb1b4c621d3c8169953f17
Reviewed-on: https://go-review.googlesource.com/c/go/+/495395
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/call.go
src/go/types/call.go
src/internal/types/testdata/check/expr3.go
src/internal/types/testdata/fixedbugs/issue39634.go

index 4b854df774ec00e1e90fbe9dd6ffacb97f251462..834d2f467fffb7254863f198847a9cc9a8ab52b5 100644 (file)
@@ -419,17 +419,6 @@ func (check *Checker) genericExprList(elist []syntax.Expr) []*operand {
 func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []Type, xlist []syntax.Expr, args []*operand) (rsig *Signature) {
        rsig = sig
 
-       // TODO(gri) try to eliminate this extra verification loop
-       for _, a := range args {
-               switch a.mode {
-               case typexpr:
-                       check.errorf(a, NotAnExpr, "%s used as value", a)
-                       return
-               case invalid:
-                       return
-               }
-       }
-
        // Function call argument/parameter count requirements
        //
        //               | standard call    | dotdotdot call |
index 313b4693460acde5efc94ee01f24154e52f0c607..3fa8cbb16c455cda815fca395615259a04948666 100644 (file)
@@ -424,17 +424,6 @@ func (check *Checker) genericExprList(elist []ast.Expr) []*operand {
 func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type, xlist []ast.Expr, args []*operand) (rsig *Signature) {
        rsig = sig
 
-       // TODO(gri) try to eliminate this extra verification loop
-       for _, a := range args {
-               switch a.mode {
-               case typexpr:
-                       check.errorf(a, NotAnExpr, "%s used as value", a)
-                       return
-               case invalid:
-                       return
-               }
-       }
-
        // Function call argument/parameter count requirements
        //
        //               | standard call    | dotdotdot call |
index da8d54fd1df2659d1ee0ce4211a02a37e23f10a7..91534cdd629b4007ce0241b7563223eddfdc7332 100644 (file)
@@ -505,7 +505,7 @@ func _calls() {
        f2(3.14) /* ERROR "not enough arguments in call to f2\n\thave (number)\n\twant (float32, string)" */
        f2(3.14, "foo")
        f2(x /* ERRORx `cannot use .* in argument` */ , "foo")
-       f2(g0 /* ERROR "used as value" */ ())
+       f2(g0 /* ERROR "used as value" */ ()) /* ERROR "not enough arguments in call to f2\n\thave (func())\n\twant (float32, string)" */
        f2(g1()) /* ERROR "not enough arguments in call to f2\n\thave (int)\n\twant (float32, string)" */
        f2(g2())
 
index 592496033bc8d06287ac1614e464384827da4973..591b00e40463338e60660cb5079d10f34a1fbe28 100644 (file)
@@ -66,7 +66,7 @@ type Z19 [][[]Z19{}[0][0]]c19 /* ERROR "undefined" */
 
 // crash 20
 type Z20 /* ERROR "invalid recursive type" */ interface{ Z20 }
-func F20[t Z20]() { F20(t /* ERROR "invalid composite literal type" */ {}) }
+func F20[t Z20]() { F20(t /* ERROR "invalid composite literal type" */ /* ERROR "too many arguments in call to F20\n\thave (unknown type)\n\twant ()" */ {}) }
 
 // crash 21
 type Z21 /* ERROR "invalid recursive type" */ interface{ Z21 }