E06290: operator declared with too few parameters

Category: E06xxx Type hierarchy checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: OPERATOR_TOO_FEW_PARAMETERS · All error codes

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

  1. Add the right-hand operand as the one parameter of the operator
  2. 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

  • E06290: operator declared with too FEW parameters (this error)
  • E06280: operator declared with too MANY parameters
  • E06310: takes NO arguments but some provided
  • E06270: a CALL with the wrong arguments

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: