E07120: base level implementation must be provided for dispatcher method

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: DISPATCHER_BUT_NO_BODY_PROVIDED · All error codes

What went wrong

A method marked as 'dispatcher' (for multiple dispatch) is missing its implementation body. Dispatcher methods need a default implementation.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 771 (Why must a dispatcher method have a body in EK9?)

How to fix it

  1. Provide default implementation for dispatcher
  2. Dispatcher needs body for fallback when no specific match
  3. Add overloads for specific type dispatching

Common causes

  • Forgot to add implementation to dispatcher
  • Thinking dispatcher works like abstract
  • Incomplete dispatcher definition

See also

  • E07120: dispatcher without body (this error)
  • E07110: non-abstract method without body
  • E07100: abstract with body

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07120: base level implementation must be provided for dispatcher method

#!ek9
defines module error.e07120.bad

  defines class

    Shape as open
      kind()
        <- rtn as String: "shape"

    Describer

      //The entry point is what runs when no more specific method matches
      describe() as dispatcher
        -> shape as Shape
        <- rtn as String?

Fixed: Give the dispatcher entry point a body

#!ek9
defines module error.e07120.good

  defines class

    Shape as open
      kind()
        <- rtn as String: "shape"

    Circle extends Shape
      override kind()
        <- rtn as String: "circle"

    Describer

      //The entry point has a body: the fallback for any Shape
      describe()
        -> circle as Circle
        <- rtn as String: "a round " + circle.kind()

      describe() as dispatcher
        -> shape as Shape
        <- rtn as String: "some " + shape.kind()

      //Chosen at run time when the Shape is a Circle

Questions and answers

These Q&A entries show E07120 and its fix: