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.

THIS EXAMPLE

The Pair class constructor takes exactly two arguments. The combine() function takes exactly two Pair 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 program

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

Common mistakes

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 triggers E06280 too many arguments?
  • What triggers E06290 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: parameters, E06290, arguments, count, constructor, mismatch, E06280, too many, function, too few