mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
go/types, types2: print variadic argument in dotdotdot form in error message
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>
This commit is contained in:
parent
9c5f5bd6d3
commit
76f3e0ac8d
@ -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
|
||||
|
@ -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
|
||||
|
15
src/internal/types/testdata/fixedbugs/issue70150.go
vendored
Normal file
15
src/internal/types/testdata/fixedbugs/issue70150.go
vendored
Normal file
@ -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) {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user