E06220: choose either empty parenthesis '( )' with values or a type definition
What went wrong
You're mixing two incompatible approaches: providing constructor VALUES and explicitly specifying the generic TYPE. EK9 requires you choose ONE:
- Provide values → compiler INFERS type
- Specify type explicitly → use empty '()' constructor
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 196 (How do I define generics with multiple type parameters in...)
Rationale
If you provide constructor arguments, the compiler infers the type from them. Specifying type explicitly would be either redundant (same type) or contradictory (different type). EK9 requires clear intent.
How to fix it
- Remove 'of Type' and let compiler infer from values
- Or remove values and use empty '()' with explicit type
- Never combine both approaches
Common causes
- Trying to be "extra explicit" by providing both type and values
- Misunderstanding type inference vs explicit typing
- Coming from languages that allow both
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06220: choose either empty parenthesis '( )' with values or a type definition
#!ek9 defines module error.e06220.bad defines class Holder of type T item as T: T() default Holder() Holder() -> initial as T item: initial default operator ? defines function mixed() //An argument already says what T is; 'of Integer' says it again holder <- Holder(32) of Integer
Fixed: Let the argument give the type: Holder(32) is a Holder of Integer
#!ek9 defines module error.e06220.good defines class Holder of type T item as T: T() default Holder() Holder() -> initial as T item: initial default operator ? defines function inferred() <- rtn as Boolean? holder <- Holder(32) rtn: holder?
Fixed: Or construct with no argument and name the type
#!ek9 defines module error.e06220.good.explicit defines class Holder of type T item as T: T() default Holder() Holder() -> initial as T item: initial default operator ? defines function explicit() <- rtn as Boolean? holder <- Holder() of Integer rtn: holder?
Questions and answers
These Q&A entries show E06220 and its fix: