E04080: Template/Generic requires parameterization

Category: E04xxx Reference checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: TEMPLATE_TYPE_REQUIRES_PARAMETERIZATION · All error codes

What went wrong

A generic type is named as a TYPE - a parameter, a return, a property or a declared variable - without its type parameters. 'List', 'Dict', 'Optional' or your own 'Box' on its own is not a type: 'List of String', 'Dict of (String, Integer)' and 'Box of String' are. ('List()' constructed with no 'of' and nothing to infer from is E06010, not this.)

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1310 (Why does EK9 reject a generic type named without 'of'...)

How to fix it

  1. Identify what type the generic should contain
  2. Add 'of TypeName' for single-parameter generics
  3. Add 'of (Type1, Type2)' for multi-parameter generics like Dict or Result

The [EXAMPLE] section below shows a generic 'Box' named alone as a parameter and a return type, then the same function with 'Box of String'.

Common causes

  • Forgetting to specify type parameter after generic name
  • Coming from dynamically-typed language where collections don't need types
  • Thinking empty collection doesn't need type specification (it does)

See also

  • E04080: MISSING type parameters on generic (this error)
  • E04070: EXTRA type parameters on non-generic type
  • E06010: a generic constructed with no type parameters and nothing to infer them from
  • E06020: WRONG NUMBER of type parameters (e.g., 1 instead of 2)

Examples

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

Fails with E04080: Template/Generic requires parameterization

#!ek9
defines module error.e04080.bad

  defines class

    Box of type T
      item as T: T()

      default Box()

      Box()
        -> initial as T
        item: initial

      default operator ?

  defines function

    unwrap()
      //'Box' alone is not a type: Box of what?
      -> container as Box
      <- rtn as Box: container

Fixed: Parameterise the generic type wherever it is used: Box of String

#!ek9
defines module error.e04080.good

  defines class

    Box of type T
      item as T: T()

      default Box()

      Box()
        -> initial as T
        item: initial

      default operator ?

  defines function

    unwrap()
      -> container as Box of String
      <- rtn as Box of String: container

Questions and answers

These Q&A entries show E04080 and its fix: