E07660: operator name cannot be used as a method

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: OPERATOR_NAME_USED_AS_METHOD · All error codes

What went wrong

You're using an operator symbol as a method name, which is invalid. Operators must use the 'operator' keyword.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 137 (How do I manage resources with try-with-resources in EK9?)

See also

  • Methods use NAMES: getLength(), process(), calculate()
  • Operators use SYMBOLS with 'operator' keyword: operator +, operator ==
  • E07660: operator symbol as method name (this error)
  • E07620: operator not defined

How to fix it

  1. Use 'operator' keyword for operators

Common causes

  • Missing 'operator' keyword
  • Trying to use symbol as method name

Examples

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

Fails with E07660: operator name cannot be used as a method

#!ek9
defines module error.e07660.bad

  defines text for "en"

    ButtonLabels
      close()
        "Close"

      contains()
        -> item as String
        `Contains ${item}`

      length()
        "Length"

      openLabel()
        "Open"

Fixed: Name a text method for what it says, never as an operator's name

#!ek9
defines module error.e07660.good.fix

  defines text for "en"

    ButtonLabels
      closeLabel()
        "Close"

      containsLabel()
        -> item as String
        `Contains ${item}`

      lengthLabel()
        "Length"

      openLabel()
        "Open"

Fixed: Name the method for what it gives

#!ek9
defines module error.e07660.good

  defines text for "en"

    ButtonLabels
      closeLabel()
        "Close"

      containsLabel()
        -> item as String
        `Contains ${item}`

      lengthLabel()
        "Length"

Questions and answers

These Q&A entries show E07660 and its fix:

Found a problem?

If EK9 reported E07660 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.