E05180: same method name as dispatcher, but marked private in super - won't be called

Category: E05xxx Explicit type symbol definition · Reported in phase: FULL_RESOLUTION · Classification: DISPATCHER_PRIVATE_IN_SUPER · All error codes

What went wrong

A dispatcher is trying to target a private method from a parent class. Private methods are not visible to child classes and cannot be dispatched to.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 849 (Why can't a dispatcher see a private handler method in a ...)

How to fix it

  1. Change target method to protected or public in parent
  2. Or use a different accessible method as dispatch target
  3. Or move the dispatch logic into the parent class

Rationale

Dispatchers route calls to implementations. If a target method is private in a parent, the child cannot access it - dispatch would fail at runtime. This is caught at compile time.

Common causes

  • Method access was changed to private after dispatcher was written
  • Assuming private methods are inherited (they're not)
  • Parent class encapsulation preventing intended dispatch

See also

  • E05180: dispatcher cannot access private target (this error)
  • E06180: general method accessibility error (not dispatch-specific)

Examples

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

Fails with E05180: same method name as dispatcher, but marked private in super - won't be called

#!ek9
defines module error.e05180.bad

  defines class

    SomeBaseClass as open

      //PRIVATE method - hidden from subclasses
      private process()
        -> input as Integer
        require input?

    BadDispatcher5 extends SomeBaseClass

      //Dispatcher entry point
      process() as dispatcher
        -> input as Any
        require input?

Fixed: Make the handler in the super protected (or public) so the dispatcher can reach it

#!ek9
defines module error.e05180.good

  defines class

    SomeBaseClass as open

      //Protected: visible to the dispatcher in the sub-type
      protected process()
        -> input as Integer
        require input?

    GoodDispatcher extends SomeBaseClass

      process() as dispatcher
        -> input as Any
        require input?

Questions and answers

These Q&A entries show E05180 and its fix: