【发布时间】:2019-04-13 06:29:29
【问题描述】:
为什么这个 panicf-sprintf 在 Golang 1.11 中会导致 type 错误? Go 没有解释原因,即使它说这是一个常见错误。
https://golang.org/doc/go1.11#vet
go vet 现在在构建期间强制执行。
func panicf(s string, i ...interface{}) { panic(fmt.Sprintf(s, i)) }
测试返回
missing ... in args forwarded to printf-like function
vet 将其描述为
func (*ptrStringer) BadWrap(x int, args ...interface{}) string {
return fmt.Sprint(args) // ERROR "missing ... in args forwarded to print-like function"
}
func (*ptrStringer) BadWrapf(x int, format string, args ...interface{}) string {
return fmt.Sprintf(format, args) // ERROR "missing ... in args forwarded to printf-like function"
请在这种情况下帮助解释 golang 中的...。
这是一个功能性游乐场:https://play.golang.org/p/DijjanQNkxK
【问题讨论】: