Skip to content

Commit 522be4e

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: remove superfluous argument test in Checker.arguments
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>
1 parent d29dd2e commit 522be4e

File tree

4 files changed

+2
-24
lines changed

4 files changed

+2
-24
lines changed

src/cmd/compile/internal/types2/call.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,6 @@ func (check *Checker) genericExprList(elist []syntax.Expr) []*operand {
419419
func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []Type, xlist []syntax.Expr, args []*operand) (rsig *Signature) {
420420
rsig = sig
421421

422-
// TODO(gri) try to eliminate this extra verification loop
423-
for _, a := range args {
424-
switch a.mode {
425-
case typexpr:
426-
check.errorf(a, NotAnExpr, "%s used as value", a)
427-
return
428-
case invalid:
429-
return
430-
}
431-
}
432-
433422
// Function call argument/parameter count requirements
434423
//
435424
// | standard call | dotdotdot call |

src/go/types/call.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,6 @@ func (check *Checker) genericExprList(elist []ast.Expr) []*operand {
424424
func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type, xlist []ast.Expr, args []*operand) (rsig *Signature) {
425425
rsig = sig
426426

427-
// TODO(gri) try to eliminate this extra verification loop
428-
for _, a := range args {
429-
switch a.mode {
430-
case typexpr:
431-
check.errorf(a, NotAnExpr, "%s used as value", a)
432-
return
433-
case invalid:
434-
return
435-
}
436-
}
437-
438427
// Function call argument/parameter count requirements
439428
//
440429
// | standard call | dotdotdot call |

src/internal/types/testdata/check/expr3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func _calls() {
505505
f2(3.14) /* ERROR "not enough arguments in call to f2\n\thave (number)\n\twant (float32, string)" */
506506
f2(3.14, "foo")
507507
f2(x /* ERRORx `cannot use .* in argument` */ , "foo")
508-
f2(g0 /* ERROR "used as value" */ ())
508+
f2(g0 /* ERROR "used as value" */ ()) /* ERROR "not enough arguments in call to f2\n\thave (func())\n\twant (float32, string)" */
509509
f2(g1()) /* ERROR "not enough arguments in call to f2\n\thave (int)\n\twant (float32, string)" */
510510
f2(g2())
511511

src/internal/types/testdata/fixedbugs/issue39634.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Z19 [][[]Z19{}[0][0]]c19 /* ERROR "undefined" */
6666

6767
// crash 20
6868
type Z20 /* ERROR "invalid recursive type" */ interface{ Z20 }
69-
func F20[t Z20]() { F20(t /* ERROR "invalid composite literal type" */ {}) }
69+
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 ()" */ {}) }
7070

7171
// crash 21
7272
type Z21 /* ERROR "invalid recursive type" */ interface{ Z21 }

0 commit comments

Comments
 (0)