E05080: inappropriate use of 'super'
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:
- ek9 -q 822 (When can I use super in EK9?)
How to fix it
- To call the parent's version of a member: 'super.member(...)'
- To pass or hold the current object as its parent type: use 'this'
- 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
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:
Found a problem?
If EK9 reported E05080 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.