E50100: incompatible category

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

What went wrong

There's a mismatch in type categories. 'Category' is a classification within a genus - more specific than genus (see E50020). The usual case is a GENERIC type or function (a template) used where a concrete one is needed: 'Shouter() extends Transformer' instead of a parameterisation, or a generic class named in a trait's 'allow only' list.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 58 (How do generic functions work in EK9?)

How to fix it

  1. Review the expected type category for the context
  2. Classes use 'with trait of' for traits, 'extends' for classes
  3. Records extend records, not classes
  4. Check generic 'constrain by' clauses for category requirements
  5. A named function cannot extend a generic function, not even a parameterisation of it ('Shouter() is Transformer of (String, String)' is a syntax error); a DYNAMIC function can be one: rtn: () is Transformer of (String, String) as function

Common causes

  • Extending a generic type or function without parameterising it
  • Type hierarchy mismatch (extending wrong category)
  • Generic constraint violation
  • Using wrong type category in inheritance

See also

  • E50100: category mismatch (this error)
  • E50020: genus mismatch (different construct kinds)
  • E50090: parameter genus mismatch

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E50100: incompatible category

#!ek9
defines module error.e50100.bad

  defines function

    Transformer() of type (K, V) as abstract
      -> item as K
      <- rtn as V?

    Shouter() extends Transformer
      -> text as String
      <- rtn as String: text.upperCase()

Fixed: Parameterise the generic - a dynamic function can be one

#!ek9
defines module error.e50100.good

  defines function

    Transformer() of type (K, V) as abstract
      -> item as K
      <- rtn as V?

    shouter()
      <- rtn as Transformer of (String, String): () is Transformer of (String, String) as function
        rtn: item.upperCase()

Questions and answers

These Q&A entries show E50100 and its fix: