E05180: same method name as dispatcher, but marked private in super - won't be called
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
- Change target method to protected or public in parent
- Or use a different accessible method as dispatch target
- 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
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: