What happens if I forget the 'override' keyword?
← Override Mechanics · Ref: Q571
If your method has the same name and signature as a parent method but you omit the 'override' keyword, the compiler reports E05120. This prevents accidental method shadowing.
THE ERROR: E05120
E05120 fires when a method matches a parent method exactly but lacks the 'override' keyword. The compiler refuses to silently shadow the parent behavior.
FIX: ADD OVERRIDE
Simply add 'override' before the method name. Before (error):
defines class Parent as open process() <- rtn as String: "parent" Child extends Parent process() // ERROR E05120 <- rtn as String: "child"
After (correct):
defines class Parent as open process() <- rtn as String: "parent" Child extends Parent override process() <- rtn as String: "child"
ALTERNATIVE: RENAME
If you intended a new method (not an override), rename it to avoid matching the parent signature.
WHY EXPLICIT OVERRIDE MATTERS
In large codebases, methods can accidentally match parent signatures after refactoring. Without mandatory override, this creates subtle bugs where the child silently replaces parent behavior. EK9 catches this at compile time.
See Q570 for override basics. See Q572 for the opposite: claiming override when nothing matches. See Q105 for method dispatch.
Example
defines module qa.override.missingkeyword defines class Greeter as open greet() as pure -> recipient as String <- rtn as String: "Hello, " + recipient farewell() as pure -> recipient as String <- rtn as String: "Goodbye, " + recipient default operator ? //Correct: override keyword is present FormalGreeter extends Greeter override greet() as pure -> recipient as String <- rtn as String: "Good day, " + recipient override farewell() as pure -> recipient as String <- rtn as String: "Farewell, " + recipient //New method: no override needed (different name) bow() as pure -> recipient as String <- rtn as String: "Bowing to " + recipient default operator ? defines program MissingOverrideDemo() stdout <- Stdout() recipientName <- "Alice" greeter <- FormalGreeter() stdout.println(greeter.greet(recipientName)) stdout.println(greeter.farewell(recipientName)) stdout.println(greeter.bow(recipientName))
Common mistakes
E05120 — When a method matches a parent method signature, omitting override causes a shadowing error. The compiler requires explicit intent. See ek9 -h E05120 for details.
Incorrect:
greet() as pure
Correct:
override greet() as pure
E05120 — farewell() has the same name and signature as Greeter.farewell(), so the override keyword is required; omitting it is E05120. See ek9 -h E05120 for details.
Incorrect:
farewell() as pure
Correct:
override farewell() as pure
Other ways to ask this
- What is E05120 does not override?
- Why does the compiler reject my method that matches the parent?
- How do I fix E05120 missing override?
Coming from another language?
Java: @Override is optional, shadowing is silent without it. Python: no override mechanism. Kotlin: override is mandatory (same as EK9). C#: override keyword required for virtual methods. EK9: override is mandatory, E05120 reported if missing.
Keywords: shadow, open, virtual, explicit, E05120, keyword, parent, abstract, inherit, override, match, missing