]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: print variadic argument in dotdotdot form in error message
authorYoulin Feng <fengyoulin@live.com>
Fri, 1 Nov 2024 03:17:49 +0000 (11:17 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 4 Nov 2024 16:26:42 +0000 (16:26 +0000)
If a variadic call to a variadic function has not enough/too many
arguments, then print the variadic argument in dotdotdot form
instead of as a slice type in the error message.

Fixes #70150

Change-Id: I81a802619b3b66195b303e2df2bafeb1433ad310
Reviewed-on: https://go-review.googlesource.com/c/go/+/624335
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/types2/call.go
src/go/types/call.go
src/internal/types/testdata/fixedbugs/issue70150.go [new file with mode: 0644]

index 4ff5fe49e76bae777269198bce5d9a2405de9f16..9095349e1d8eafe8bdfebed6e6017dc308acfb13 100644 (file)
@@ -530,7 +530,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
                }
                err := check.newError(WrongArgCount)
                err.addf(at, "%s arguments in call to %s", qualifier, call.Fun)
-               err.addf(nopos, "have %s", check.typesSummary(operandTypes(args), false))
+               err.addf(nopos, "have %s", check.typesSummary(operandTypes(args), ddd))
                err.addf(nopos, "want %s", check.typesSummary(varTypes(params), sig.variadic))
                err.report()
                return
index bb7d0bd0d3f0bb08143761eb99dadd117634118b..459e927f7ebf7ed59fdb6f9db40f80ea6c2069ed 100644 (file)
@@ -530,7 +530,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
                }
                err := check.newError(WrongArgCount)
                err.addf(at, "%s arguments in call to %s", qualifier, call.Fun)
-               err.addf(noposn, "have %s", check.typesSummary(operandTypes(args), false))
+               err.addf(noposn, "have %s", check.typesSummary(operandTypes(args), ddd))
                err.addf(noposn, "want %s", check.typesSummary(varTypes(params), sig.variadic))
                err.report()
                return
diff --git a/src/internal/types/testdata/fixedbugs/issue70150.go b/src/internal/types/testdata/fixedbugs/issue70150.go
new file mode 100644 (file)
index 0000000..ea308cf
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _() {
+       var values []int
+       vf(values /* ERROR "(variable of type []int) as string value" */)
+       vf(values...) /* ERROR "have (...int)" */
+       vf("ab", "cd", values /* ERROR "have (string, string, ...int)" */ ...)
+}
+
+func vf(method string, values ...int) {
+}