E50020: incompatible genus
What went wrong
You're using a construct of one 'genus' where a different genus is required. In EK9, 'genus' refers to the fundamental KIND of construct.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 97 (What is the difference between classes and records in EK9?)
- ek9 -q 103 (What are abstract classes and methods in EK9?)
- ek9 -q 115 (How do dynamic classes work in EK9?)
- ek9 -q 111 (What are components in EK9?)
- ek9 -q 114 (How do aspects work with components for AOP?)
[EK9 CONSTRUCT GENUS TYPES]
- CLASS - Standard class with state and behavior
- RECORD - Data-focused type (like a struct)
- TRAIT - Interface/mixin for composition
- FUNCTION - Standalone callable function
- COMPONENT - Injectable service component
- SERVICE - Web service definition
- PROGRAM - Entry point program
- TYPE - Constrained type alias
- ENUMERATION - Enumerated type
How to fix it
- Ensure construct genus matches requirements
- Classes extend classes, records extend records
- Classes/records implement traits, not other classes
Common causes
- Extending a record with a class (records extend records)
- Implementing a class as a trait (traits implement traits)
- Using a function where a class is expected
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E50020: incompatible genus
#!ek9 defines module error.e50020.bad defines class Greeter extends greeting describe() <- rtn as String: "greeter" defines function greeting() <- rtn as String: "hello"
Fixed: A class extends a class, never a function
#!ek9 defines module error.e50020.good.fix defines class Greeter describe() <- rtn as String: "greeter" defines function greeting() <- rtn as String: "hello"
Fixed: A class extends a class (a function extends a function)
#!ek9 defines module error.e50020.good defines class Base as open describe() <- rtn as String: "base" Greeter extends Base override describe() <- rtn as String: "greeter"
Questions and answers
These Q&A entries show E50020 and its fix:
- Q97: What is the difference between classes and records in EK9?
- Q102: How do I make a class extensible with 'as open'?
- Q103: What are abstract classes and methods in EK9?
- Q111: What are components in EK9?
- Q114: How do aspects work with components for AOP?
- Q115: How do dynamic classes work in EK9?
- Q197: How do I extend or specialize a generic type in EK9?
- Q808: How do I mock dependencies in EK9 tests without Mockito?
- Q1129: Delegate trait methods to another object using the 'by' keyword.