]> Cypherpunks repositories - gostls13.git/commitdiff
vet: be less strict about number of arguments when a ... is present.
authorDavid Symonds <dsymonds@golang.org>
Thu, 6 Dec 2012 04:17:31 +0000 (15:17 +1100)
committerDavid Symonds <dsymonds@golang.org>
Thu, 6 Dec 2012 04:17:31 +0000 (15:17 +1100)
R=golang-dev
CC=golang-dev
https://golang.org/cl/6883046

src/cmd/vet/print.go

index 0a9e45dc8a8ce1dcdfc4d3ef947890630be12195..0ec01721a5080188fa9137bdd5a23cd0638812e1 100644 (file)
@@ -120,6 +120,10 @@ func (f *File) checkPrintf(call *ast.CallExpr, name string, skip int) {
                }
        }
        expect := len(call.Args) - (skip + 1)
+       // Don't be too strict on dotdotdot.
+       if call.Ellipsis.IsValid() && numArgs >= expect {
+               return
+       }
        if numArgs != expect {
                f.Badf(call.Pos(), "wrong number of args in %s call: %d needed but %d args", name, numArgs, expect)
        }
@@ -280,6 +284,7 @@ func BadFunctionUsedInTests() {
        fmt.Printf("%s%%%d", "hi", 3)      // correct
        fmt.Printf("%.*d", 3, 3)           // correct
        fmt.Printf("%.*d", 3, 3, 3)        // ERROR "wrong number of args in Printf call"
+       fmt.Printf("%q %q", multi()...)    // ok
        printf("now is the time", "buddy") // ERROR "no formatting directive"
        Printf("now is the time", "buddy") // ERROR "no formatting directive"
        Printf("hi")                       // ok
@@ -297,3 +302,8 @@ func BadFunctionUsedInTests() {
 func printf(format string, args ...interface{}) {
        panic("don't call - testing only")
 }
+
+// multi is used by the test.
+func multi() []interface{} {
+       panic("don't call - testing only")
+}