E01086: aggregate member out of order - EK9 requires: properties first, then methods, then operators (a bare 'default operator' last)
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
- E07235: an aggregate with properties must define its own '?'
- E01084: Prefix operator used in suffix position
- E01085: Suffix operator used in prefix position
- https://ek9.io/classes.html
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:
- Q1090: Define a PaymentRequest that is only 'set' when all three fields are present.
- Q1097: Create a Product class with full operator support in one line.
- Q1098: Generate all operators with default, but customise the string representation.
- Q1195: How do I define an Event record with Date, Time, and String fields and compare two events?
- Q1204: Define an Employee record with name, hire date, and department, then sort employees by hire date.