E06020: type/function is generic, but incorrect number of parameters supplied

Category: E06xxx Type hierarchy checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: GENERIC_TYPE_OR_FUNCTION_PARAMETERS_INCORRECT · All error codes

What went wrong

You provided type parameters, but the wrong number. Each generic type expects a specific number of type parameters - you must provide exactly that many.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 198 (What built-in generic types does EK9 provide?)
  • ek9 -q 58 (How do generic functions work in EK9?)
  • ek9 -q 167 (How do I iterate over Dict entries safely without worryin...)
  • ek9 -q 194 (How do I define a generic class in EK9?)
  • ek9 -q 198 (What built-in generic types does EK9 provide?)

Generic type parameter counts

Single parameter generics (use 'of T'):

  • List of T - element type
  • Optional of T - contained type
  • Iterator of T - yielded type

Two parameter generics (use 'of (T1, T2)'):

  • Dict of (K, V) - key type, value type
  • Result of (T, E) - success type, error type
  • DictEntry of (K, V) - key type, value type
  • Function of (T, R) - input type, return type

How to fix it

  1. Check the generic type's definition for parameter count
  2. Adjust your 'of' clause to provide exactly that many types
  3. Remember: single = 'of T', multiple = 'of (T1, T2)'

Common causes

  • Forgetting Dict needs both key AND value types
  • Treating single-param generic like two-param
  • Copy-pasting from different generic type

See also

  • E06020: WRONG NUMBER of type parameters (this error)
  • E06010: MISSING type parameters entirely
  • E04070/E04080: earlier phase type parameter issues

Examples

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

Fails with E06020: type/function is generic, but incorrect number of parameters supplied

#!ek9
defines module error.e06020.bad

  defines function

    declaredTypes()
      <- rtn as Integer?
      //List takes one type argument, not two
      numbers as List of (Integer, Date): List()

      //Dict takes two type arguments: key and value
      lookup as Dict of (Integer): Dict()
      rtn: length numbers + length lookup

    constructedTypes()
      <- rtn as Integer?
      numbers <- List() of (Integer, Date)

      lookup <- Dict() of (Integer)
      rtn: length numbers + length lookup

Fixed: Give each generic the number of type arguments it takes: List one, Dict two

#!ek9
defines module error.e06020.good.fix

  defines function

    declaredTypes()
      <- rtn as Integer?
      //List takes one type argument, not two
      numbers as List of Integer: List()

      //Dict takes two type arguments: key and value
      lookup as Dict of (Integer, String): Dict()
      rtn: length numbers + length lookup

    constructedTypes()
      <- rtn as Integer?
      numbers <- List() of Integer

      lookup <- Dict() of (Integer, String)
      rtn: length numbers + length lookup

Fixed: Give each generic exactly as many type arguments as it declares: List one, Dict two

#!ek9
defines module error.e06020.good

  defines function

    declaredTypes()
      <- rtn as Integer?
      numbers as List of Integer: List()
      lookup as Dict of (Integer, String): Dict()
      rtn: length numbers + length lookup

    constructedTypes()
      <- rtn as Integer?
      names <- List() of String
      dates <- Dict() of (String, Date)
      rtn: length names + length dates

Questions and answers

These Q&A entries show E06020 and its fix: