E05080: inappropriate use of 'super'

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

What went wrong

You're using 'super' in a form it cannot take. 'super' is only a way to reach the PARENT's version of a member - 'super.describe()', or an operator on it such as '$super' or 'super?'. It is not a value of its own:

  • 'theSuper <- super', 'theSuper := super' or passing 'super' as an argument is rejected - use 'this' (which already IS the parent type)
  • 'super()' where there is no constructor to call it from, such as 'register super()' in an application

A class (or trait) with no explicit parent is a different error: there, any 'super' reaches only the implicit Any base and is E05040.

Worked examples

Compilable examples demonstrating this error and the correct fix:

How to fix it

  1. To call the parent's version of a member: 'super.member(...)'
  2. To pass or hold the current object as its parent type: use 'this'
  3. In an application: register a real component, not 'super()'

The [EXAMPLE] section below shows 'super' held and passed as a value, then 'super.describe()' in an override and 'this' passed where the parent type is wanted.

Rationale

'super' names where member lookup starts, not a separate object. The object is 'this'; holding 'super' as a value would only be 'this' under a misleading name.

Common causes

  • Treating 'super' as a reference to a separate parent object
  • Passing 'super' to a method that takes the parent type

See also

  • E05080: 'super' used as a value or outside a constructor (this error)
  • E05040: 'super' where the only parent is the implicit Any base
  • E05060: 'super()' call outside a constructor

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E05080: inappropriate use of 'super'

#!ek9
defines module error.e05080.bad

  defines class

    Base as open
      label as String: "base"

      describe()
        <- rtn as String: label

      default operator ?

    Derived extends Base
      extra as String: "derived"

      compare()
        -> other as Base
        <- rtn as Boolean: other.describe() == describe()

      misuse()
        <- rtn as Boolean?

        //'super' is not a value: it cannot be held
        parent <- super

        //Nor passed as an argument
        rtn: compare(super)

      default operator ?

Fixed: Pass 'this' (a Derived is a Base), and use super only to call the parent's method

#!ek9
defines module error.e05080.good

  defines class

    Base as open
      label as String: "base"

      describe()
        <- rtn as String: label

      default operator ?

    Derived extends Base
      extra as String: "derived"

      compare()
        -> other as Base
        <- rtn as Boolean: other.describe() == describe()

      override describe()
        <- rtn as String: `${super.describe()} and ${extra}`

      selfCheck()
        <- rtn as Boolean: compare(this)

      default operator ?

Questions and answers

These Q&A entries show E05080 and its fix: