E06290: operator declared with too few parameters
What went wrong
An OPERATOR is DECLARED with too few parameters. A binary operator such as '+' or '==' must take exactly one parameter, the right-hand operand (the left-hand operand is 'this'); declaring it with none leaves nothing to operate with. This error is about the DECLARATION of the operator. It is not about a call: a call that passes the wrong number of arguments is E06270 (or E50060 when nothing matches).
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 779 (Why must certain operators return a value in EK9?)
How to fix it
- Add the right-hand operand as the one parameter of the operator
- If the operation takes no operand, use an operator that takes none ('?', '$', '#?', 'length') or a method
Common causes
- Declaring '+', '==' or '<=>' with no parameter
- Forgetting the right-hand operand because the left-hand one is 'this'
- Declaring a unary form of an operator that has only a binary one
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06290: operator declared with too few parameters
#!ek9 defines module error.e06290.bad defines class Amount total as Integer: 0 default Amount() as pure //'+' needs the right-hand operand default operator ? operator + as pure <- rtn as Amount: Amount()
Fixed: Give the binary operator its one parameter
#!ek9 defines module error.e06290.good defines class Amount total as Integer? default private Amount() as pure Amount() as pure -> initial as Integer total :=? initial default operator ? operator + as pure -> other as Amount <- rtn as Amount: Amount(total + other.total)
Questions and answers
These Q&A entries show E06290 and its fix:
Found a problem?
If EK9 reported E06290 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.