Why does EK9 reject calls with the wrong number of arguments?

← Classes and OOP · Ref: Q781

EK9 enforces exact argument counts at compile time. A function or method defined with two parameters must be called with exactly two arguments — no more, no fewer.

NO DEFAULT PARAMETERS

Unlike Python or Kotlin, EK9 does not support default parameter values. Every parameter must be explicitly provided at the call site.

NO VARARGS

Unlike Java or Python, EK9 does not support variable argument lists. If you need flexible argument counts, use a List parameter.

ERRORS

Calling a function with the wrong number of arguments is E06270 (parameter mismatch). Calling a method or constructor with the wrong number of arguments is E50060 (not resolved).

THIS EXAMPLE

The Pair class constructor takes exactly two arguments. The plus() function takes exactly two Integer arguments.

WHY STRICT COUNTS

1. No ambiguity about which overload is called
2. No hidden default values that change behaviour silently
3. Every call site is explicit and self-documenting

See Q48 for why no default parameters. See Q49 for why no varargs. See Q89 for constructors.

Example

defines module qa.classesandoop.argumentcount

  defines class

    Pair
      label <- String()
      count <- Integer()

      Pair()
        ->
          l as String
          c as Integer
        label :=: l
        count :=: c

      describe()
        <- rtn as String: `${label}=${count}`

      default operator ?

  defines function

    plus() as pure
      ->
        a as Integer
        b as Integer
      <- rtn as Integer: a + b

  defines program

    ShowPair()
      stdout <- Stdout()
      pair <- Pair("hello", 42)
      if pair?
        stdout.println(pair.describe())

      first <- 20
      second <- 22
      total <- plus(first, second)
      stdout.println(`Total: ${total}`)

Common mistakes

E06270 — The plus function requires exactly two arguments but three were supplied, so the call is a parameter mismatch. Remove the extra argument. See ek9 -h E06270 for details.

Incorrect:

      total <- plus(first, second, first)

Correct:

      total <- plus(first, second)

E50060 — The Pair constructor requires two arguments (String and Integer) but only one was provided. The compiler cannot resolve a Pair(String) constructor. Provide all required arguments. See ek9 -h E50060 for details.

Incorrect:

      pair <- Pair("hello")

Correct:

      pair <- Pair("hello", 42)

E50060 — The Pair constructor requires two arguments but three were provided. The compiler cannot resolve a Pair(String, Integer, Boolean) constructor. Remove the extra argument. See ek9 -h E50060 for details.

Incorrect:

      pair <- Pair("hello", 42, true)

Correct:

      pair <- Pair("hello", 42)
Other ways to ask this
  • What error do I get when I call a function with too many arguments?
  • What error do I get when I call a constructor with too few arguments?
  • How do I fix argument count mismatch in EK9?

Coming from another language?

Java: method overloading provides multiple argument counts, varargs with '...'. Python: default values, *args, **kwargs. Rust: no default params, no varargs. Kotlin: default parameter values, varargs. Go: no default params, variadic with '...'. EK9: no defaults, no varargs, strict argument count enforcement.

Keywords: constructor, count, arguments, E06270, parameters, E50060, too few, function, too many, mismatch