Go

Fix Go "Too Many Arguments" and "Not Enough Arguments in Call" — Call Arity, Variadic Functions, and the Spread Operator

A call is a promise about numbers before it is a promise about types: the function declares how many arguments it takes, and the call has to supply exactly that many, no more and no fewer. The compiler counts first and types second, so a call with the wrong count fails even when every argument it does pass has exactly the right type. Each section below takes one shape, shows the exact message it prints, and gives the fix that belongs to that shape.

Written November 19, 2026 · Tested with Go 1.26.4 · 21 min read

By the end of this guide
  • The first error: one argument too many
  • One argument too few
  • A function that takes no arguments
  • The same count on a method

What this guide is

too many arguments in call to add and not enough arguments in call to add are the compiler counting, not judging. A function signature is a fixed list of parameters — func add(a, b int) int takes two — and a call has to supply exactly that many arguments. Three arguments to a two-parameter function is one too many; one argument is one too few. The count is checked before the types are: add(1, 2, 3) fails even though every argument is an int, because the third argument has no parameter to land on. The message says so in two lines underneath the first: have lists the types of the arguments the call supplied, and want lists the types of the parameters the function declares. Read those two lines against each other and the fix is usually visible: an argument to drop, a parameter to supply, or a signature to change.

One wording point first, because the two messages name the same defect from opposite sides. too many arguments means the call supplied more than the signature declares; not enough arguments means it supplied fewer. Both print the same have and want lines, and both point at the call. The position sits inside the call: when there is an extra argument, it points at the first extra one — the 3 in add(1, 2, 3) is at column 24, the 2 in c.Add(1, 2) is at column 11, the "x" in hello("x") is at column 8. When the count is short, it points at the call itself: the function name when there are no arguments at all, as in Greeting() at column 14, and the first argument when one is present, as in add(1) at column 18. The line number always names the call, and the column names the argument where the count first goes wrong.

The examples here use Go 1.26.4. Every example lives in a single file named main.go inside one module, created once from an empty directory:

Terminal
$ mkdir callarity
$ cd callarity
$ go mod init example.com/callarity
go: creating new go.mod: module example.com/callarity

Each program that follows replaces the contents of that main.go. When a build fails, the compiler prints the module path as a header line above the error — # example.com/callarity here.

The first error: one argument too many

The smallest program that earns the message calls a two-parameter function with three arguments:

Go
// main.go
package main

import "fmt"

func add(a, b int) int {
    return a + b
}

func main() {
    fmt.Println(add(1, 2, 3))
}
Terminal
$ go build
# example.com/callarity
./main.go:10:24: too many arguments in call to add
    have (number, number, number)
    want (int, int)

The have line lists three number values: the arguments 1, 2, and 3 are untyped constants, and the compiler reports their kind rather than a declared type. The want line lists the two parameters the signature declares, both int. The mismatch is in the count — three against two — not in the types: every argument supplied is a number, and a number is assignable to int, so the types would have passed. The position, column 24, is the 3, the first argument with no parameter waiting for it. The fix is to drop the extra argument, add(1, 2), or to give the function a third parameter if the call is the one that is right. Which side is wrong is a design decision the compiler cannot make: it can count, and it reports the count, and the author decides whether the call or the signature gives way.

One argument too few

The mirror image calls the same function with one argument:

Go
// main.go
package main

import "fmt"

func add(a, b int) int {
    return a + b
}

func main() {
    fmt.Println(add(1))
}
Terminal
$ go build
# example.com/callarity
./main.go:10:18: not enough arguments in call to add
    have (number)
    want (int, int)

The have line now lists one number against a want of two int values, and the position, column 18, is the 1, the argument the call did supply. Go has no default arguments: a parameter with no argument has no value, and the compiler does not invent one. The fix is to supply the missing argument, add(1, 2), or to change the signature so the function takes one parameter. There is no third option in which the missing parameter silently takes its zero value — a missing argument is a compile error, not a default.

A function that takes no arguments

The same counting applies at zero. A function with an empty parameter list takes no arguments at all, and a call that supplies one fails with the same message, with an empty want:

Go
// main.go
package main

import "fmt"

func hello() {
    fmt.Println("hello")
}

func main() {
    hello("x")
}
Terminal
$ go build
# example.com/callarity
./main.go:10:8: too many arguments in call to hello
    have (string)
    want ()

The want () is the empty parameter list written out, and the position, column 8, is the "x", the one argument with nowhere to go. The have line shows string because a string literal has type string, unlike the untyped numbers in the earlier cases. The fix is to drop the argument, hello(), or to give hello a parameter to receive it. A common source of this shape is a function that used to take an argument and no longer does: the call sites that still pass it are the ones this message finds.

The same count on a method

A method call is counted the same way, with the receiver left out of the count. The receiver is not an argument — it is the value the method is called on — so c.Add(1, 2) is counted as two arguments against one parameter, not three against two:

Go
// main.go
package main

import "fmt"

type Counter struct{ n int }

func (c *Counter) Add(n int) { c.n += n }

func main() {
    c := &Counter{}
    c.Add(1, 2)
    fmt.Println(c.n)
}
Terminal
$ go build
# example.com/callarity
./main.go:11:11: too many arguments in call to c.Add
    have (number, number)
    want (int)

The message names the call c.Add, receiver included, but the want line lists only the declared parameter, one int. The position, column 11, is the 2, the first extra argument. The fix is the same as for a plain function: c.Add(1). The receiver is never the argument that is too many — if the receiver itself were wrong, the message would be a different one, about the method set, not about the count.

The same count on a function value

A variable that holds a function is counted against the function type the variable declares, not against the function literal that was assigned to it:

Go
// main.go
package main

import "fmt"

func main() {
    f := func(n int) int { return n * 2 }
    fmt.Println(f(1, 2))
}
Terminal
$ go build
# example.com/callarity
./main.go:7:19: too many arguments in call to f
    have (number, number)
    want (int)

The message names the variable f, and the want line is the single int parameter of its type, func(int) int. The position, column 19, is the 2. The fix is f(1), or a wider function type for f if the call needs two arguments. The same rule covers a function passed as an argument to another function, or returned from one: wherever a function value is called, the count is checked against the type the value is known by at that call site.

The built-in len: a different message for the same defect

The built-in functions are not ordinary functions — the specification says they are predeclared, called like any other function, but without standard Go types — and an arity mistake on one of them prints a different message. len takes exactly one argument, and a second one earns this:

Go
// main.go
package main

import "fmt"

func main() {
    fmt.Println(len(1, 2))
}
Terminal
$ go build
# example.com/callarity
./main.go:6:14: invalid operation: too many arguments for len(1, 2) (expected 1, found 2)

There is no have and want here. The message is a single line, it names the call as written — len(1, 2) — and it states the count directly: expected 1, found 2. The position, column 14, is the len name itself rather than an argument. The fix is the same in substance: len("hello"), one argument, or whichever single value was meant to be measured. The same form appears for the other fixed-arity built-ins: copy takes exactly two arguments, and a third earns the same invalid operation wording. append, by contrast, is variadic, so extra arguments to it are legal — the count that fails for len is not a count at all for append.

Variadic functions: the fixed parameter still counts

A variadic function — one whose final parameter is written ...T — may be called with zero or more arguments for that final parameter, but its fixed parameters still count exactly. Greeting below takes one fixed parameter, a prefix, and then any number of names:

Go
// main.go
package main

import "fmt"

func Greeting(prefix string, who ...string) string {
    return prefix + fmt.Sprint(who)
}

func main() {
    fmt.Println(Greeting())
}
Terminal
$ go build
# example.com/callarity
./main.go:10:14: not enough arguments in call to Greeting
    have ()
    want (string, ...string)

The want line shows the variadic parameter as ...string, and the have line is empty — no arguments at all were supplied, so even the fixed prefix is missing. The position, column 14, is the Greeting name, because there is no argument for the position to point at. The fix is to supply the prefix, Greeting("hi:"), which compiles: the variadic parameter takes zero arguments, and the specification says that when a variadic function is invoked with no actual arguments for its final parameter, the value passed for it is nil. The program below proves the zero case compiles and runs, printing 0 for no numbers and 3 for two:

Go
// main.go
package main

import "fmt"

func sum(nums ...int) int {
    total := 0
    for _, n := range nums {
        total += n
    }
    return total
}

func main() {
    fmt.Println(sum())
    fmt.Println(sum(1, 2))
}
Terminal
$ go run main.go
0
3

The contrast to hold on to is that zero is a legal count only for the variadic parameter. A fixed parameter with no argument is always not enough arguments, however many variadic arguments follow it. Greeting("Joe", "Anna") without a prefix is not a call with two names and a missing prefix — it is a call with the prefix "Joe" and one name, and it compiles, printing the wrong greeting. The compiler counts positions, not intentions.

A slice without ... is one argument, not many

The spread operator ... is what turns a slice into the individual arguments of a variadic call, and without it a slice is a single argument of slice type. Passing s, a []int, where the variadic parameter wants individual int values fails — but not with an arity message. The count is right — one argument for one parameter — and the type is wrong:

Go
// main.go
package main

import "fmt"

func sum(nums ...int) int {
    total := 0
    for _, n := range nums {
        total += n
    }
    return total
}

func main() {
    s := []int{1, 2, 3}
    fmt.Println(sum(s))
}
Terminal
$ go build
# example.com/callarity
./main.go:15:18: cannot use s (variable of type []int) as int value in argument to sum

The message is the type error from the companion guide, not an arity error: cannot use s ... as int value in argument to sum. The compiler read s as one argument of type []int offered for a parameter of type int, and refused it. The fix is the spread operator, sum(s...), which passes the slice unchanged as the value for the ...int parameter — the specification says that when the final argument is assignable to a slice type []T and is followed by ..., it is passed unchanged, and no new slice is created. The program below proves the spread form compiles and runs, printing 6:

Go
// main.go
package main

import "fmt"

func sum(nums ...int) int {
    total := 0
    for _, n := range nums {
        total += n
    }
    return total
}

func main() {
    nums := []int{1, 2, 3}
    fmt.Println(sum(nums...))
}
Terminal
$ go run main.go
6

The spread operator on a function that is not variadic

The reverse mistake is using ... on a call to a function whose final parameter is an ordinary parameter, not a variadic one. The compiler refuses the spread itself, before it ever counts the elements:

Go
// main.go
package main

import "fmt"

func add(a, b int) int {
    return a + b
}

func main() {
    nums := []int{1, 2, 3}
    fmt.Println(add(nums...))
}
Terminal
$ go build
# example.com/callarity
./main.go:11:14: cannot use ... in call to non-variadic add

The message names the defect directly — cannot use ... in call to non-variadic add — and the position, column 14, is the add name. There is no have or want, because the call never got as far as counting: ... is only meaningful where a ...T parameter waits for it. The fix depends on what was intended. To add the first two elements, index them: add(nums[0], nums[1]). To add all of them, the function has to change — either to a variadic sum as in the previous section, or to a loop at the call site. Note the count would have failed anyway: three elements against two parameters is one too many, so even a variadic reading of this call would not have saved it.

The one exception: passing a call's return values directly

There is exactly one call shape in which the argument count is not checked against the parameter list one argument at a time. The specification's Calls section gives it as a special case: if the return values of a function g are equal in number and individually assignable to the parameters of another function f, then the call f(g(...)) invokes f after passing the return values of g to the parameters of f in order — and the call of f must contain no parameters other than the call of g. The program below is the specification's own example shape, and it compiles and runs, printing true:

Go
// main.go
package main

import "fmt"

func Split(s string, pos int) (string, string) {
    return s[0:pos], s[pos:]
}

func Join(s, t string) string { return s + t }

func main() {
    value := "hello"
    fmt.Println(Join(Split(value, len(value)/2)) == value)
}
Terminal
$ go run main.go
true

Split returns two strings and Join takes two strings, so the two return values land on the two parameters in order. The exception is narrow: the call of f must contain nothing but the call of g, so Join(Split(value, 2), "!") fails — the extra argument breaks the special case, and the compiler reports the two return values as a multiple value in a single-value context — and a g that returns one value passed to a two-parameter f fails with not enough arguments, the single value counted against two parameters. A single call as the sole argument is the only form in which one written argument stands for several parameters, and it is the only shape in this guide where counting the written arguments gives the wrong answer.

The fixed program

The program below applies every fix at once: the extra arguments are dropped, the missing prefix is supplied, len takes one argument, the function value takes one, and the slice is spread onto the variadic function:

Go
// main.go
package main

import "fmt"

type Counter struct{ n int }

func (c *Counter) Add(n int) { c.n += n }

func add(a, b int) int { return a + b }

func sum(nums ...int) int {
    total := 0
    for _, n := range nums {
        total += n
    }
    return total
}

func Greeting(prefix string, who ...string) string {
    return prefix + fmt.Sprint(who)
}

func main() {
    fmt.Println(add(1, 2))
    c := &Counter{}
    c.Add(1)
    fmt.Println(c.n)
    fmt.Println(len("hello"))
    f := func(n int) int { return n * 2 }
    fmt.Println(f(3))
    fmt.Println(Greeting("hi:"))
    fmt.Println(Greeting("hi:", "Joe", "Anna"))
    nums := []int{1, 2, 3}
    fmt.Println(sum(nums...))
}
Terminal
$ go run main.go
3
1
5
6
hi:[]
hi:[Joe Anna]
6

The output is 3, 1, 5, 6, hi:[], hi:[Joe Anna], and 6. Each line exercises one fix: add(1, 2) is 3; the counter takes one argument and holds 1; len("hello") is 5; the function value doubles 3 to 6; Greeting("hi:") has no names, so the variadic parameter is nil and prints as the empty slice []; Greeting("hi:", "Joe", "Anna") prints both names; and the spread slice sums to 6.

The fixes, ranked

Drop the extra argument, or supply the missing one. This is the fix for the plain cases — too many, not enough, and the zero-argument function called with one. Count the parameters in the signature, count the arguments in the call, and make the two lists the same length. It is the most common repair, because most arity errors are a call that drifted away from a signature that is still right.

Change the signature when the call is right. This is the fix when the call site is the one that knows what it needs: a function that should take a third parameter, or a parameter that should no longer exist. The compiler reports the count; it cannot tell which side is stale. Look at the other call sites before deciding — if every call passes three arguments and the function takes two, the signature is the outlier.

Give a variadic function its fixed arguments first, and let the variadic parameter take zero. This is the fix for the Greeting() shape. The prefix is a fixed parameter and has to be supplied; the names may be zero, one, or many. A call that omits the prefix has not supplied a short variadic list — it has supplied no prefix at all.

Spread the slice, or index it. This is the fix for the two ... shapes. A slice passed to a variadic function needs ... after it, sum(s...), or it is one argument of slice type. A slice spread onto a non-variadic function needs the spread removed and the elements indexed, add(nums[0], nums[1]), or the function changed to variadic.

Do not add a parameter to len, and do not count append like len. The built-ins have their own arity, fixed by the language: len takes exactly one argument, copy takes exactly two, and append takes a slice plus zero or more values because it is variadic. An arity error on a built-in is fixed at the call, not by changing anything about the built-in.

Which fix for which cause

What the code shows Cause Fix
Three arguments to a two-parameter function One argument too many Drop the extra argument, or add a parameter
One argument to a two-parameter function One argument too few Supply the missing argument, or drop a parameter
An argument to a function with no parameters The parameter list is empty Drop the argument, or add a parameter
An extra argument to a method The receiver is not counted Drop the extra argument after the receiver
An extra argument to a function value Counted against the variable's function type Drop the extra argument, or widen the type
A second argument to len Built-ins have fixed arity and their own message Pass one argument
No arguments to a variadic function with a fixed parameter The fixed parameter still counts Supply the fixed argument; the variadic one may be zero
A slice passed to a variadic function without ... The slice is one argument of slice type Spread it: sum(s...)
... on a call to a non-variadic function The spread has no variadic parameter to land on Index the elements, or make the function variadic
One call passed as the sole argument The multi-return special case Nothing to fix; the return values spread onto the parameters
A value of the wrong type in an argument The count is right, the type is wrong Fix the type, not the count

Checklist

  • Read the have and want lines first: they state the count on both sides, and the fix is usually visible in the difference. A have longer than the want means an argument to drop; a shorter one means an argument to supply.
  • Read the position: for too many it points at the first extra argument, so the argument at that column is the one with no parameter. For not enough it points at the call itself, so the missing argument has no column to point at.
  • Check whether the parameter is variadic before counting: a ...T parameter takes zero or more arguments, and a call with none for it compiles. A fixed parameter before it still has to be supplied, exactly once.
  • Check whether the argument is a slice before reaching for ...: a slice without ... is one argument, and the error it earns is a type error, not an arity error. A ... without a variadic parameter earns its own message before any counting happens.
  • Check the built-ins separately: len and copy have fixed arity and print invalid operation with expected and found, not have and want. append is variadic, so extra arguments to it are not an error at all.
  • When the count is right and the call still fails, the defect is the type, not the number — and when a single call is the sole argument, the multi-return special case may be the shape that already works.

Sources

  • The Go Programming Language Specification — for calls (given an expression f of function type F, f(a1, a2, … an) calls f with arguments a1, a2, … an, and, except for one special case, arguments must be single-valued expressions assignable to the parameter types of F; a method invocation is similar but the method itself is specified as a selector upon a value of the receiver type; and the special case, where the return values of a function g are equal in number and individually assignable to the parameters of another function f, so the call f(g(...)) invokes f after passing the return values of g to the parameters of f in order, the call of f containing no parameters other than the call of g), for function types (a function signature may have a final parameter prefixed with ..., and a function with such a parameter is called variadic and may be invoked with zero or more arguments for that parameter), for passing arguments to parameters (if f is variadic with a final parameter p of type ...T, then within f the type of p is equivalent to type []T; if f is invoked with no actual arguments for p, the value passed to p is nil; otherwise the value passed is a new slice of type []T whose successive elements are the actual arguments; and if the final argument is assignable to a slice type []T and is followed by ..., it is passed unchanged as the value for a ...T parameter), and for built-in functions (built-in functions are predeclared, called like any other function, but do not have standard Go types, so they can only appear in call expressions; append is variadic, appending zero or more values to a slice).

Keep Exploring