E05250: abstract type cannot be in 'allow only' list — only concrete classes are permitted
What went wrong
An abstract class has been listed in a trait's 'allow only' clause. The 'allow only' clause defines the exhaustive set of concrete runtime types that may implement the sealed trait. Abstract classes cannot be instantiated, so listing them in 'allow only' is meaningless — they can never be concrete runtime instances of the trait.
Abstract classes ARE allowed to implement sealed traits (they are exempt from the E05240 enforcement check). But they should not appear in the 'allow only' list itself, because the list should enumerate only the concrete types that the developer intends to exist at runtime.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 850 (Can an abstract class appear in a trait's allow only list?)
How to fix it
Remove the abstract class from the 'allow only' list. The list should contain only concrete classes that are intended as the complete set of runtime implementations. Abstract classes can still implement the trait freely — they just should not appear in the permitted list.
Common causes
- Listing a base class that was later made abstract during refactoring
- Confusing 'allow only' (concrete runtime types) with 'extends' hierarchy
- Including an abstract helper class that intermediates between the trait and concrete implementations
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E05250: abstract type cannot be in 'allow only' list — only concrete classes are permitted
#!ek9 defines module error.e05250.bad defines trait Workable allow only AbstractHelper, ConcreteWorker process() as abstract defines class AbstractHelper as abstract doWork() as abstract ConcreteWorker doWork() content <- "Working" require content?
Fixed: List only concrete classes after 'allow only'
#!ek9 defines module error.e05250.good defines trait Workable allow only ConcreteWorker, OtherWorker process() as abstract defines class ConcreteWorker with trait of Workable override process() content <- "Working" require content? OtherWorker with trait of Workable override process() content <- "Also working" require content?
Questions and answers
These Q&A entries show E05250 and its fix: