How does EK9 reject constructing a program or application, and abstract types in sealed allow only lists?
← Code Quality · Ref: Q744
EK9 validates two specific type constraint patterns at compile time.
INCOMPATIBLE GENUS CONSTRUCTOR (E05200)
A program or an application cannot be created with a constructor call ('app <- OrderApp()'). A program is the entry point the runtime starts, and an application is the dependency-injection blueprint that a program binds with 'with application of'; neither is an ordinary object.
ABSTRACT IN ALLOW ONLY (E05250)
Sealed traits use 'allow only' to restrict which concrete types can implement them. Abstract classes cannot appear in this list because they can never be instantiated as concrete runtime types. Only concrete classes that can actually exist at runtime belong in the allow only list.
CORRECT PATTERNS
Bind a program to its application with 'with application of' instead of constructing either. For sealed traits, list only concrete classes in the allow only clause.
See Q679 for sealed allow only. See Q1312 for programs and applications.
Example
defines module qa.codequality.genericsealedconstraints defines class ConcreteAlpha doWork() content <- "Alpha" require content? default operator ConcreteBeta doWork() content <- "Beta" require content? default operator defines trait //Correct: only concrete classes in allow only list Processable allow only ConcreteAlpha, ConcreteBeta process() as abstract defines program GenericSealedDemo() stdout <- Stdout() //Correct generic usage names <- List() of String names += "Alice" names += "Bob" stdout.println(`Names: ${length names}`)
Common mistakes
E50010 — AbstractWorker does not exist in this module. Adding an unresolved type to the allow only list triggers E50010. See ek9 -h E50010 for details.
Incorrect:
Processable allow only ConcreteAlpha, AbstractWorker, ConcreteBeta
Correct:
Processable allow only ConcreteAlpha, ConcreteBeta
E06010 — List is a generic type that requires a type parameter. Use 'List() of String' for explicit typing. See ek9 -h E06010 for details.
Incorrect:
names <- List()
Correct:
names <- List() of String
Other ways to ask this
- What is E05200 incompatible genus constructor in EK9?
- What is E05250 abstract in allow only in EK9?
- Why does EK9 reject abstract classes in sealed trait allow only lists?
Coming from another language?
Java: generic constraints via bounded wildcards, no sealed trait equivalent until Java 17. Kotlin: sealed classes restrict subclassing. Rust: trait bounds on generics. Swift: no sealed traits. EK9: compile-time enforcement of both the program/application genus rule and sealed trait allow only lists.
Keywords: only, constructor, quality, abstract, E05250, generic, allow, E05200, sealed, constraint