Why does EK9 report E06320 when a dispatcher handler has a different number of parameters from the entry?

← Dispatcher Validation · Ref: Q1344

A dispatcher distributes a single call across handler methods of the same name, selecting the handler by the runtime type(s) of the argument(s). Every handler must therefore have the SAME number of parameters as the dispatcher entry method. If the entry takes one parameter but a handler takes two (or zero), the compiler cannot line the arguments up at the dispatch point and reports E06320 (invalid number of parameters). The dispatcher entry itself must also declare one or two parameters; zero or more than two is rejected with the same error.

FIX: give every handler exactly the same parameter count as the entry. If a handler genuinely needs extra data, pass it into the dispatcher entry too (a two-parameter dispatcher), or carry it on the argument object, so all overloads stay aligned.

See Q619 for two-parameter dispatch and Q105 for method dispatch.

Example

defines module qa.dispatcher.handler.parametercount

  defines class

    Shape as abstract
      area() as pure abstract
        <- rtn as Float?
      default operator ?

    Circle extends Shape
      override area() as pure
        <- rtn as Float: 3.14
      default operator ?

    Square extends Shape
      override area() as pure
        <- rtn as Float: 4.0
      default operator ?

    //CORRECT: the dispatcher entry takes one parameter, and EVERY handler
    //also takes exactly one parameter of the same arity. The handler is
    //selected at run time by the actual type of the single argument.
    AreaReporter
      report() as pure dispatcher
        -> shape as Shape
        <- rtn as String: `Shape area ${shape.area()}`

      report() as pure
        -> shape as Circle
        <- rtn as String: `Circle area ${shape.area()}`

      report() as pure
        -> shape as Square
        <- rtn as String: `Square area ${shape.area()}`

  defines program

    DispatcherParameterCountDemo()
      stdout <- Stdout()
      reporter <- AreaReporter()
      stdout.println(reporter.report(Circle()))
      stdout.println(reporter.report(Square()))

Common mistakes

E06320 — The dispatcher entry report takes one parameter, so every handler must also take exactly one parameter. A two-parameter handler cannot be aligned with the single-argument dispatch site, so the compiler reports E06320. Keep all handlers at the entry's arity (or make the entry two-parameter too). See ek9 -h E06320 for details.

Incorrect:

report() as pure
        ->
          shape as Circle
          unit as String

Correct:

report() as pure
        -> shape as Circle
Other ways to ask this
  • What triggers E06320 invalid number of parameters on a dispatcher?
  • Why must every dispatcher handler have the same parameter count as the entry?
  • How do I fix a dispatcher handler that takes too many parameters?

Coming from another language?

Java/Kotlin: overloaded methods may freely vary their parameter counts; the compiler picks an overload at compile time by static type, so arity differences are normal. EK9 dispatchers select a handler at run time by the argument's actual type, so all handlers must share the entry's arity - a difference is a compile-time error (E06320) rather than a silent overload.

Keywords: parameter, count, entry, handler, overload, invalid number of parameters, arity, dispatcher, E06320, dispatch