E04080: Template/Generic requires parameterization
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
- Identify what type the generic should contain
- Add 'of TypeName' for single-parameter generics
- 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
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: