E50020: incompatible genus

Category: E50xxx Common errors · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: INCOMPATIBLE_GENUS · All error codes

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

  1. Ensure construct genus matches requirements
  2. Classes extend classes, records extend records
  3. 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

  • E50020: wrong construct genus (this error)
  • E50030: wrong type (same genus, different type)

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: