E06090: a named dynamic class cannot be used within a generic type/function
What went wrong
Named dynamic classes cannot be defined inside generic types or functions. Use anonymous dynamic classes (assign to variable) or define named classes outside the generic context.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 648 (Why cannot I use named dynamic classes inside a generic t...)
Rationale
Named types inside generics create ambiguity about type scope and parameterization. When a generic is instantiated with different type parameters, named inner classes would create conflicting type definitions. Anonymous dynamic classes avoid this by having no name to conflict.
How to fix it
- Remove the type name from dynamic class: use 'helper <- ()' not 'MyHelper <- ()'
- Or define named classes outside the generic scope
- Reference external named types from within generics
Key syntax difference
WRONG: MyHelper <- () is Interface as class // Named - creates type RIGHT: helper <- () is Interface as class // Anonymous - just a variable
Common causes
- Wanting to name a type for clarity (use comments instead)
- Habit from languages allowing named inner classes
- Not realizing lowercase is variable name, not type name
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06090: a named dynamic class cannot be used within a generic type/function
#!ek9 defines module error.e06090.bad defines trait Processor process() -> text as String <- rtn as String: text defines class Container of type T handle() -> item as T <- rtn as String? require item? //A NAMED dynamic class would be one class shared by every 'Container of X' processor as Processor: NamedProcessor() with trait of Processor as class override process() -> text as String <- rtn as String: `processed: ${text}` rtn: processor.process("item")
Fixed: Leave the dynamic class anonymous inside a generic type or function
#!ek9 defines module error.e06090.good defines trait Processor process() -> text as String <- rtn as String: text defines class Container of type T handle() -> item as T <- rtn as String? require item? processor as Processor: () with trait of Processor as class override process() -> text as String <- rtn as String: `processed: ${text}` rtn: processor.process("item")
Questions and answers
These Q&A entries show E06090 and its fix: