E07177: the super type has no accessible no-argument constructor (it is 'private', or there is none), so a default constructor cannot be generated here - you must define a constructor for this sub-type that calls an accessible super(...)
What went wrong
A sub-type defines no constructor at all, and its super has no accessible no-argument constructor: it is 'private', or there is none. EK9 would normally generate a public no-argument default constructor, but its hidden super() could not reach one - so no default is created and the type would be unconstructable.
A super has NO no-argument constructor when it is itself a sub-type of a base whose no-argument constructor is private: EK9 generates one only when the super has an accessible one, all the way down a chain.
How to fix it
- Define a constructor for this sub-type that calls an accessible super(...) (the [EXAMPLE] section below: Sample takes an Integer and passes it on)
- Or make the base's no-argument constructor accessible (public/protected)
Common causes
- Extending a base that declares 'default private Base()' (its properties are uninitialised, see E07175) without providing your own constructor
- Relying on the auto-generated no-argument default constructor, which cannot be created when the super's no-argument constructor is private or missing
- Extending a sub-type of such a base (a three-level chain): the middle type has no no-argument constructor either
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07177: the super type has no accessible no-argument constructor (it is 'private', or there is none), so a default constructor cannot be generated here - you must define a constructor for this sub-type that calls an accessible super(...)
#!ek9 defines module error.e07177.bad defines class Reading as open amount as Integer? default private Reading() Reading() -> initial as Integer this.amount: initial default operator ? //No constructor, and none can be generated: it would have to call the private Reading() Sample extends Reading describe() <- rtn as String: "a sample"
Fixed: Define a constructor that calls an accessible super(...)
#!ek9 defines module error.e07177.good defines class Reading as open amount as Integer? default private Reading() Reading() -> initial as Integer this.amount: initial default operator ? Sample extends Reading Sample() -> initial as Integer super(initial) describe() <- rtn as String: "a sample"
Questions and answers
These Q&A entries show E07177 and its fix: