E07070: traits do not support constructor methods
What went wrong
You're defining a constructor in a TRAIT, but traits cannot have constructors - only classes can create instances.
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?)
How to fix it
- Remove constructor from trait
- Use default values for initialization
- Move construction logic to implementing class
Common causes
- Treating trait like a class
- Trying to initialize trait state
- Misunderstanding trait capabilities
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07070: traits do not support constructor methods
#!ek9 defines module error.e07070.bad defines trait Nameable //A trait is never constructed on its own Nameable()
Fixed: Construct the class that has the trait
#!ek9 defines module error.e07070.good defines trait Nameable name() as abstract <- rtn as String? defines class Person with trait of Nameable personName as String? default private Person() Person() -> newName as String this.personName: newName override name() <- rtn as String: personName default operator ?
Questions and answers
These Q&A entries show E07070 and its fix:
Found a problem?
If EK9 reported E07070 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.