E07290: only constructors and operators methods are supported on records
What went wrong
You're defining a regular method on a RECORD, but records can only have constructors and operators - not methods.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 97 (What is the difference between classes and records in EK9?)
- ek9 -q 98 (How do record operators work in EK9?)
- ek9 -q 119 (What EK9 constructs are available and when should I use e...)
Rationale
RECORDS are for pure DATA. Classes are for BEHAVIOR.
How to fix it
- Use CLASS instead if you need methods
- Or use standalone functions with record
Common causes
- Treating record like a class
- Trying to add behavior to data type
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07290: only constructors and operators methods are supported on records
#!ek9 defines module error.e07290.bad defines record Point x <- 0 y <- 0 //A record carries data; behaviour belongs in a function or a class moveBy() -> distance as Integer <- rtn as Point: Point(x + distance, y + distance) default operator ?
Fixed: Take the method out of the record: a record holds data and operators, behaviour belongs in a function or a class
#!ek9 defines module error.e07290.good.fix defines record Point x <- 0 y <- 0 default operator ?
Fixed: Use an operator, or a function over the record
#!ek9 defines module error.e07290.good defines record Point x as Integer? y as Integer? default private Point() as pure Point() as pure -> across as Integer down as Integer this.x :=? across this.y :=? down //Operators are allowed on a record default operator ? operator + as pure -> other as Point <- rtn as Point: Point(x + other.x, y + other.y) defines function //The behaviour is a function over the record moveBy() as pure -> point as Point distance as Integer <- rtn as Point: point + Point(distance, distance)
Questions and answers
These Q&A entries show E07290 and its fix:
- Q97: What is the difference between classes and records in EK9?
- Q98: How do record operators work in EK9?
- Q119: What EK9 constructs are available and when should I use each?
- Q1175: Define a Product record with name, price, and a constructor.
- Q1198: Calculate an end date from a start date and a duration gap on a Project class.
- Q1297: Can records extend other records in EK9?
Found a problem?
If EK9 reported E07290 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.