E07050: 'abstract' modifier on a constructor is not logical
What went wrong
You've marked a constructor as 'abstract', but constructors MUST create instances - they can never be abstract.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 774 (Why can't a constructor be abstract in EK9?)
How to fix it
- Remove 'abstract' from constructor
- Use abstract factory method if you need polymorphic creation
- Constructors always create instances
Common causes
- Confusion between constructors and factory methods
- Trying to defer construction to subclasses
- Misunderstanding abstract semantics
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07050: 'abstract' modifier on a constructor is not logical
#!ek9 defines module error.e07050.bad defines class Counter as abstract //A constructor makes an object, so it cannot be abstract Counter() as abstract -> start as Integer
Fixed: A constructor makes an object, so it is never abstract: give it a body
#!ek9 defines module error.e07050.good.fix defines class Counter as abstract //A constructor makes an object, so it cannot be abstract Counter() -> start as Integer require start?
Fixed: Give the constructor a body
#!ek9 defines module error.e07050.good defines class Counter count as Integer? default private Counter() Counter() -> start as Integer this.count: start default operator ?
Questions and answers
These Q&A entries show E07050 and its fix:
Found a problem?
If EK9 reported E07050 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.