E07090: 'default' modifier is only valid for constructors, not regular methods
What went wrong
You've used 'default' modifier on a regular METHOD, but 'default' is only valid for constructors and operators.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 109 (How do I use composition instead of inheritance in EK9?)
How to fix it
- Remove 'default' from method
- Provide explicit implementation
- Use 'default' only on constructors or operators
Common causes
- Confusion about 'default' keyword purpose
- Trying to provide auto-generated method
- Misunderstanding which constructs support default
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07090: 'default' modifier is only valid for constructors, not regular methods
#!ek9 defines module error.e07090.bad defines record R1 prop1 <- String() //Valid: default constructor default R1() //A record holds constructors and operators, not methods default getValue() <- rtn as String: String(prop1) //Valid: a default operator default operator ? defines trait T1 //Valid: abstract method without default anotherMethod() as pure abstract -> text as String <- rtn as String? //A method is written, never 'default' default someMethod() as pure -> text as String <- rtn as String: String(text) defines class C1 //Valid: default constructor default C1() //A method is written, never 'default' default normalMethod() -> text as String <- rtn as String: String(text) //Valid: regular method without default validMethod() -> text as String <- rtn as String: String(text) defines component Comp1 //Valid: default constructor default Comp1() //A method is written, never 'default' default processData() -> payload as String <- rtn as String: String(payload)
Fixed: Take 'default' off each method; a record holds operators, so its member becomes operator $
#!ek9 defines module error.e07090.good.fix defines record R1 prop1 <- String() //Valid: default constructor default R1() //A record holds constructors and operators, not methods operator $ as pure <- rtn as String: String(prop1) //Valid: a default operator default operator ? defines trait T1 //Valid: abstract method without default anotherMethod() as pure abstract -> text as String <- rtn as String? //A method is written, never 'default' someMethod() as pure -> text as String <- rtn as String: String(text) defines class C1 //Valid: default constructor default C1() //A method is written, never 'default' normalMethod() -> text as String <- rtn as String: String(text) //Valid: regular method without default validMethod() -> text as String <- rtn as String: String(text) defines component Comp1 //Valid: default constructor default Comp1() //A method is written, never 'default' processData() -> payload as String <- rtn as String: String(payload)
Fixed: Remove 'default' from the method
#!ek9 defines module error.e07090.good defines class Greeter //'default' is fine on a constructor default Greeter() //A method is written, never 'default' greet() -> greeting as String <- rtn as String: String(greeting)
Questions and answers
These Q&A entries show E07090 and its fix:
Found a problem?
If EK9 reported E07090 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.