Why does EK9 reject override on constructs that cannot override?
← Code Quality · Ref: Q826
EK9 rejects the override keyword on constructs that do not support inheritance-based overriding. Programs and service methods cannot override anything.
WHERE OVERRIDE IS INVALID
- Programs: programs are entry points, not extendable
- Service methods: services do not inherit from other services
WHERE OVERRIDE IS VALID
- Class methods that replace a parent class method
- Trait method implementations in classes
- Function extensions that replace a parent function
WHY THIS MATTERS
The override keyword is a contract: 'I intend to replace a parent implementation.' Using it on a construct that has no parent hierarchy is a logic error caught at compile time.
See Q96 for inheritance. See Q155 for testing.
Example
defines module qa.quality.override.check defines program OverrideCheckDemo() stdout <- Stdout() stdout.println("Programs cannot use override")
Common mistakes
E05100 — Programs cannot use override — they are entry points with no parent to override. Remove the override keyword. See ek9 -h E05100 for details.
Incorrect:
override OverrideCheckDemo()
Correct:
OverrideCheckDemo()
Other ways to ask this
- What is E05100 OVERRIDE_INAPPROPRIATE?
- Why can't I use override on a program in EK9?
- Where is the override keyword not allowed in EK9?
Coming from another language?
Java: @Override on a static method or constructor is a compile error. Kotlin: override keyword validated against parent. C++: override specifier checked. Python: no enforcement. EK9: override validated at SYMBOL_DEFINITION phase.
Keywords: program, E05100, inheritance, inappropriate, service, override