E06210: parenthesis '( )' required in this context
What went wrong
You're trying to create an INSTANCE of a generic type but missing the '()'. In EK9, '()' is required to construct/instantiate. Without it, you're just referencing the TYPE, not creating an instance.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 681 (What is the correct syntax for generic type parameterizat...)
Parentheses after the type arguments
'List of String()' puts the '()' after the type arguments, so it reads as a call of the type 'List of String', which has no '()' of its own. It has one reading - the parentheses belong to the generic's name: 'List() of String', 'Dict() of (String, Integer)', and for a generic function 'echo() of Integer' (each form is in the [EXAMPLE] section below). The message names the fix ("write 'List() of String'"), and the editing tools (ek9_compile, ek9_edit_file, ek9_write_file) rewrite it for you. By hand: move the '()' to just after the generic's name.
How to fix it
- Add '()' after the generic type name to create an instance
- If declaring type only, use 'as TypeName' syntax
- Check whether you need instance or just type reference
Common causes
- Writing 'List of String()' - the '()' after the type arguments
- Writing 'List of String' when you want to CREATE a List
- Missing '()' after generic type in assignment/statement context
- Confusion between type reference and instantiation
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06210: parenthesis '( )' required in this context
#!ek9 defines module error.e06210.bad defines function echo() of type T as pure -> item as T <- rtn as T: item <?- Valid: the parentheses before the type arguments. -?> ValidForm() names <- List() of String counts <- Dict() of (String, Integer) require names? and counts? OneTypeArgument() names <- List of String() TwoTypeArguments() counts <- Dict of (String, Integer)() NestedTypeArgument() nested <- List of List of String() GenericFunction() echoed <- echo of Integer()
Fixed: Put the parentheses before the type arguments: List() of String
#!ek9 defines module error.e06210.good defines function echo() of type T as pure -> item as T <- rtn as T: item validForm() <- rtn as Integer? names <- List() of String counts <- Dict() of (String, Integer) nested <- List() of List of String echoed <- echo() of Integer rtn: length names + length counts + length nested + echoed(1)
Questions and answers
These Q&A entries show E06210 and its fix:
Found a problem?
If EK9 reported E06210 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.