What is the complete set of dispatcher compile-time checks?
← Dispatcher Validation · Ref: Q621
EK9 performs six distinct compile-time checks on dispatchers, catching errors that would be runtime failures in other languages.
PURITY MATCHING (E05170)
All handlers must match the dispatcher entry's purity. A pure dispatcher requires all handlers to be pure. A non-pure dispatcher requires all handlers to be non-pure.
ACCESS VALIDATION (E05180)
Dispatcher handlers must be accessible. A dispatcher in a child class cannot target a private method in the parent class.
TYPE HIERARCHY (E05210)
Every handler's parameter type must be a subtype of the entry's parameter type. Handlers for unrelated types are rejected.
RETURN TYPE (E05220)
All handlers must return the same type (or a covariant subtype) as the entry method.
AMBIGUITY DETECTION (E05230)
When two handlers match at equal cost (especially with multiple trait implementations), the compiler rejects the ambiguity rather than guessing.
EXHAUSTIVE COVERAGE (E05260)
Dispatchers on sealed types (with 'allow only') must have handlers for all permitted concrete types.
TOGETHER
These six checks guarantee that at runtime, every dispatch call will find exactly one valid handler with correct purity, access, type, and return type. No runtime dispatch errors are possible.
See Q612 for E05170. See Q613 for E05180. See Q614 for E05210. See Q615 for E05220. See Q616 for E05230. See Q618 for E05260.
Example
defines module qa.dispatchervalidation.summary defines trait //Sealed trait for exhaustive dispatch demo Action allow only SaveAction, LoadAction perform() as pure abstract <- rtn as String? defines class SaveAction with trait of Action override perform() as pure <- rtn as String: "saved" LoadAction with trait of Action override perform() as pure <- rtn as String: "loaded" //Dispatcher demonstrating multiple checks passing ActionRunner //Pure dispatcher (E05170 check: all handlers pure) run() as pure dispatcher -> action as Action <- rtn as String: action.perform() //Handler type in hierarchy (E05210 check) //Return type matches (E05220 check) //Exhaustive coverage (E05260 check: both SaveAction and LoadAction handled) run() as pure -> action as SaveAction <- rtn as String: "Running save: " + action.perform() run() as pure -> action as LoadAction <- rtn as String: "Running load: " + action.perform() defines function testDispatcherChecks() runner <- ActionRunner() saveAction <- SaveAction() loadAction <- LoadAction() require runner.run(saveAction) == "Running save: saved" require runner.run(loadAction) == "Running load: loaded"
Common mistakes
E05170 — The dispatcher entry run is declared as pure. Every handler must match this purity level. Omitting as pure on a handler creates a purity mismatch. See ek9 -h E05170 for details.
Incorrect:
run()
-> action as SaveAction
Correct:
run() as pure -> action as SaveAction
E50060 — String has no toUpperCase() method in EK9. Use upperCase() instead. See ek9 -h E50060 for details.
Incorrect:
require runner.run(saveAction).toUpperCase() == "Running save: saved"
Correct:
require runner.run(saveAction) == "Running save: saved"
E50001 — The dispatcher entry takes Action. All handler parameter types must be subtypes of Action. String is outside the Action hierarchy. See ek9 -h E50001 for details.
Incorrect:
run() as pure -> item as String
Correct:
run() as pure -> action as SaveAction
Other ways to ask this
- What dispatcher errors can EK9 detect?
- How does EK9 validate dispatchers at compile time?
- What are all the dispatcher-related E05xxx error codes?
Coming from another language?
Java: only static overload resolution, no runtime dispatch validation. Kotlin: exhaustive when on sealed types only. Rust: exhaustive match on enums but no multi-dispatch. Julia: multiple dispatch with runtime ambiguity errors. Python: singledispatch with no compile-time validation. EK9: six compile-time dispatch checks eliminate all runtime dispatch errors.
Keywords: E05170, validation, E05210, E05260, validate, dispatch, compile, summary, E05230, E05180, dispatcher, ambiguity, E05220