E037: Overrides Nothing

This error is emitted when a member is declared with the override modifier but there is no corresponding member in a superclass to override.

There must be a field or method with the same name in a super class to override it. This error typically occurs when:

  • The member name is misspelled
  • The wrong class is being extended
  • The parent class doesn't have a member with that name

Example

class Parent:
  def greet(): String = "Hello"

class Child extends Parent:
  override def greeet(): String = "Hi"

Error

-- [E037] Declaration Error: example.scala:5:15 --------------------------------
5 |  override def greeet(): String = "Hi"
  |               ^
  |               method greeet overrides nothing
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | There must be a field or method with the name greeet in a super
  | class of class Child to override it. Did you misspell it?
  | Are you extending the right classes?
   -----------------------------------------------------------------------------

Solution

// Fix the spelling to match the parent method
class Parent:
  def greet(): String = "Hello"

class Child extends Parent:
  override def greet(): String = "Hi"
// Or remove the override modifier if not overriding
class Parent:
  def greet(): String = "Hello"

class Child extends Parent:
  def greeet(): String = "Hi"