E07075: traits do not support properties/fields
What went wrong
You're defining a property/field in a TRAIT, but traits are stateless behaviour contracts and cannot have properties. Only classes, records, and components can hold state.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 106 (What are traits and how do I use them in EK9?)
- ek9 -q 105 (How does method dispatch work in EK9?)
How to fix it
- Remove property from trait
- Define abstract accessor methods instead
- Move state to implementing class
Common causes
- Treating trait like a class with state
- Trying to share default values across implementations
- Misunderstanding trait purpose (behaviour, not state)
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07075: traits do not support properties/fields
#!ek9 defines module error.e07075.bad defines trait Nameable //A trait holds behaviour, never state personName <- "default"
Fixed: Declare an abstract method on the trait, and the property on the class
#!ek9 defines module error.e07075.good defines trait Nameable name() as abstract <- rtn as String? defines class Person with trait of Nameable personName <- "default" override name() <- rtn as String: personName default operator ?
Questions and answers
These Q&A entries show E07075 and its fix: