E05120: as it overrides method of same name/signature in hierarchy
What went wrong
Your method or operator has the same name and signature as one in a parent class, a trait, or the root type, but you did not write 'override'. EK9 requires the keyword whenever a parent member is being replaced.
The commonest case is 'operator ?' on a class, record or component: every aggregate inherits '?' from the root type, so your '?' always overrides it and must be 'override operator ? as pure'. Other operators ('$', '+', ...) only need 'override' when a parent actually defines them - adding it where nothing is being overridden is E05110.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1068 (I get E05120 saying override is required on my operator...)
- ek9 -q 1070 (Which operators always need the override keyword in EK9?)
- ek9 -q 102 (How do I make a class extensible with 'as open'?)
- ek9 -q 1068 (I get E05120 saying override is required on my operato...)
- ek9 -q 96 (How do operators work in EK9?)
- ek9 -q 60 (What is function dispatching in EK9?)
How to fix it
- Add 'override' to the member the error names (e.g. 'override operator ? as pure').
- If you did NOT mean to replace the parent's member: rename yours.
- Add 'override' only where a parent member exists - the mirror error, E05110, fires when 'override' has nothing to override.
Rationale
Explicit 'override' makes replacement visible to readers and lets the compiler catch a parent-signature change (the override then stops matching and fails loudly, instead of silently becoming a new method). "Explicit over implicit" - and it is enforced both ways, with E05110.
Common causes
- 'operator ?' on a class, record or component without 'override' (it always overrides the root's)
- Implementing a trait method without 'override'
- Copy-pasting a parent method into a subclass
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E05120: as it overrides method of same name/signature in hierarchy
#!ek9 defines module error.e05120.bad defines class Shape as open describe() <- description as String: "a shape" Circle extends Shape describe() <- description as String: "a circle"
Fixed: Say override when the signature matches the super's
#!ek9 defines module error.e05120.good defines class Shape as open describe() <- description as String: "a shape" Circle extends Shape override describe() <- description as String: "a circle"
Questions and answers
These Q&A entries show E05120 and its fix:
- Q60: What is function dispatching in EK9?
- Q96: How do operators work in EK9?
- Q102: How do I make a class extensible with 'as open'?
- Q103: What are abstract classes and methods in EK9?
- Q105: How does method dispatch work in EK9?
- Q106: What are traits and how do I use them in EK9?
- Q107: Can a class implement multiple traits in EK9?
- Q108: How do I implement a trait for my class?
- Q109: How do I use composition instead of inheritance in EK9?
- Q110: What is the difference between a trait and an abstract class?
- Q111: What are components in EK9?
- Q112: How do services work in EK9 for REST and HTTP?
- Q114: How do aspects work with components for AOP?
- Q115: How do dynamic classes work in EK9?
- Q117: How do I create a singleton in EK9?
- Q210: How does trait delegation with 'by' work in EK9?
- Q263: How do I implement the factory pattern in EK9?
- Q264: How do I implement the adapter pattern in EK9?
- Q266: How do I handle cross-cutting concerns in EK9?
- Q281: How do I verify AI-generated EK9 code?
- Q298: What is allow only on traits in EK9?
- Q299: How does allow only work with dispatchers in EK9?
- Q300: Can abstract classes be in an allow only list in EK9?
- Q301: How do I restrict which classes can extend my class in EK9?
- Q302: How do dispatchers work with sealed classes in EK9?
- Q303: Can a permitted subclass also be sealed in EK9?
- Q561: Why must an override of a pure method also be pure?
- Q568: How does purity apply to operators and their overrides?
- Q570: What does 'override' mean in EK9 and when is it required?
- Q571: What happens if I forget the 'override' keyword?
- Q572: What happens if I claim 'override' but no parent method matches?
- Q574: What happens if I try to extend or override in a closed type?
- Q575: How do overrides work in deep class hierarchies?
- Q576: How do overrides work when a class implements a trait and extends a parent?
- Q577: How do I override operators in EK9?
- Q578: What is the relationship between open, abstract, and override?
- Q579: How do overrides work in a three-level trait hierarchy?
- Q591: How do function hierarchies compare to class hierarchies?
- Q602: What is a circular type hierarchy and why does EK9 ban it?
- Q603: How does EK9 detect multi-level circular inheritance chains?
- Q604: Do traits, records, and components also check for circular hierarchies?
- Q606: What is method shadowing and how does EK9 handle it?
- Q607: Must a class with 'allow only' be declared as open?
- Q608: How do sealed classes differ from sealed traits in EK9?
- Q609: Can sealed enforcement work across module boundaries?
- Q610: How do I refactor circular dependencies using composition?
- Q611: What is the full set of type hierarchy checks EK9 performs?
- Q617: How can trait diamond patterns cause dispatcher ambiguity?
- Q676: How do override and access modifiers interact in a three-level class hierarchy?
- Q1051: Can a trait define comparison and hashcode operators in EK9?
- Q1068: I get E05120 saying override is required on my operator ?. How do I fix it?
- Q1069: Can I use default operator and also define my own operator ? on the same class?
- Q1070: Which operators always need the override keyword in EK9?
- Q1131: Resolve diamond inheritance when a class adopts two traits that share a parent.
- Q1133: Delegate operators through a trait so the delegating class supports $ and ?.
- Q1176: Implement a Describable trait with a name method in a concrete Animal class.
- Q1297: Can records extend other records in EK9?