E07810: Dispatch only supported in classes
What went wrong
You're using 'dispatcher' keyword outside of a class context. Dispatch (multiple dispatch pattern) is only supported in classes.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 106 (What are traits and how do I use them in EK9?)
How to fix it
- Move dispatcher method to a class
- Dispatch pattern requires class instance context
Common causes
- Dispatcher in function
- Dispatcher in trait
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07810: Dispatch only supported in classes
#!ek9 defines module error.e07810.bad defines trait Describer //Dispatch chooses a method on a class's actual argument types describe() as dispatcher -> shape as Shape <- rtn as String: shape.kind() defines class Shape as open kind() <- rtn as String: "shape"
Fixed: Put the dispatcher on a class
#!ek9 defines module error.e07810.good defines class Shape as open kind() <- rtn as String: "shape" Circle extends Shape override kind() <- rtn as String: "circle" Describer describe() -> circle as Circle <- rtn as String: "a round " + circle.kind() describe() as dispatcher -> shape as Shape <- rtn as String: "some " + shape.kind()
Questions and answers
These Q&A entries show E07810 and its fix: