E01086: aggregate member out of order - EK9 requires: properties first, then methods, then operators (a bare 'default operator' last)

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: AGGREGATE_MEMBER_OUT_OF_ORDER · All error codes

What went wrong

A member of an aggregate body (class, record, trait, component or dynamic class) is out of the order EK9 requires:

  • Properties (fields) first
  • Constructors and methods second
  • Operators third, in any order among themselves ('default operator X' is one)
  • A bare 'default operator' (generate every operator) is the LAST item of all

The compiler reports the FIRST member out of that order, once per body, on the member itself: a method or property after an operator, a property after a method, or anything after a bare 'default operator'. The failing source in the [EXAMPLE] section below (bad.ek9) declares 'describe()' after 'default operator ?'.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1097 (Create a Product class with full operator support in o...)

Common causes

  • Adding a new method at the end of a class without noticing operators above
  • Reorganizing methods and accidentally placing one after operators
  • Copy-pasting code blocks below the operator section
  • Adding a property at the end of a class, below its methods

How to fix it

Move the member up to where its kind belongs:

  • A method goes above every 'operator' and 'default operator' line (good.ek9 below)
  • A property goes above the methods
  • An explicit operator goes above a bare 'default operator', which stays the LAST line of the body (good_bare_default.ek9 below)

See also

Examples

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

Fails with E01086: aggregate member out of order - EK9 requires: properties first, then methods, then operators (a bare 'default operator' last)

#!ek9
defines module error.e01086.bad

  defines class

    Product
      name <- String()
      price <- Float()

      default operator ?

      describe()
        <- rtn as String: `${name} at ${price}`

Fixed: Move the method up: properties, then methods, then operators

#!ek9
defines module error.e01086.good

  defines class

    Product
      name <- String()
      price <- Float()

      describe()
        <- rtn as String: `${name} at ${price}`

      default operator ?

Fixed: A bare 'default operator' is the last item: explicit operators go above it

#!ek9
defines module error.e01086.good.bare.default

  defines class

    Product
      name <- String()
      price <- Float()

      describe() as pure
        <- rtn as String: `${name} at ${price}`

      operator $ as pure
        <- rtn as String: describe()

      default operator

Questions and answers

These Q&A entries show E01086 and its fix:

Found a problem?

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