E06020: type/function is generic, but incorrect number of parameters supplied
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
- Check the generic type's definition for parameter count
- Adjust your 'of' clause to provide exactly that many types
- 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
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:
- Q45: How does the List type work in EK9?
- Q58: How do generic functions work in EK9?
- Q167: How do I iterate over Dict entries safely without worrying about missing keys?
- Q194: How do I define a generic class in EK9?
- Q198: What built-in generic types does EK9 provide?
- Q654: How does EK9 validate the number of type parameters for generics?
- Q1158: Iterate over a Dict and print each key-value pair.
- Q1161: Add entries to a Dict, look up a value by key, and iterate over all entries.
- Q1243: Write me a generic Transformer class with two type parameters K and V, and a dynamic class implementation that maps String keys to Integer values via a transform method.
Found a problem?
If EK9 reported E06020 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.