E05120: as it overrides method of same name/signature in hierarchy

Category: E05xxx Explicit type symbol definition · Reported in phase: FULL_RESOLUTION · Classification: METHOD_OVERRIDES · All error codes

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

  1. Add 'override' to the member the error names (e.g. 'override operator ? as pure').
  2. If you did NOT mean to replace the parent's member: rename yours.
  3. 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

  • E05120: parent member matches but 'override' is MISSING (this error)
  • E05110: 'override' declared but NO parent member matches (the mirror case)
  • E05100: 'override' on a program/service method, which can never be extended

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: