E50090: incompatible genus in parameter(s)
What went wrong
A DISPATCHER handler takes a parameter of a different genus (fundamental KIND of construct) from the dispatcher entry point's parameter in the same position. A handler is only ever reached with an argument that arrived through the entry point, so it must be the same kind of thing: a CLASS entry point cannot route to a RECORD or FUNCTION handler. A class trait and its classes are compatible (that is the point of dispatching over a trait), as are an abstract function and the functions that extend it. See E50020 for genus types (CLASS, RECORD, TRAIT, FUNCTION, etc.).
This is NOT the error for passing the wrong kind of argument to a call - a class instance passed where a function is expected is E06270 (function) or E50060 (method).
How to fix it
- Give the handler a parameter of the same genus as the dispatcher's
- Or widen the dispatcher's parameter (for example to 'Any') so every handler type can reach it
- If the method is not meant to be a handler, give it a different name
The [EXAMPLE] section below shows a dispatcher over Integer (a CLASS) with a handler for a RECORD, and the dispatcher widened to Any so the Holder handler can be reached.
Common causes
- Adding a handler for a record or function to a dispatcher over a class hierarchy
- Reusing the dispatcher's method name for an unrelated overload
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E50090: incompatible genus in parameter(s)
#!ek9 defines module error.e50090.bad defines record Holder count as Integer: 1 default operator ? defines class Router route() -> item as Holder <- rtn as String: "holder" route() as dispatcher -> item as Integer <- rtn as String: "integer"
Fixed: Give the dispatcher entry point a parameter every handler is compatible with
#!ek9 defines module error.e50090.good defines record Holder count as Integer: 1 default operator ? defines class Router route() as dispatcher -> item as Any <- rtn as String: "any" route() -> item as Holder <- rtn as String: "holder"
Questions and answers
These Q&A entries show E50090 and its fix: