E07410: returning type must be same as the construct type
What went wrong
A constructor's return type doesn't match the enclosing class type. Constructors must return instances of their own class.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 864 (Why must the negate operator ~ return the same type as it...)
- ek9 -q 823 (Why must certain operators return specific types in EK9?)
How to fix it
- Return type must match enclosing class name
Common causes
- Typo in return type
- Copy/paste error
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07410: returning type must be same as the construct type
#!ek9 defines module error.e07410.bad defines class Toggle on <- false //'~' returns the type it is declared on, never another default operator ? operator ~ as pure <- rtn as Boolean: not on
Fixed: Return the type that declares the operator
#!ek9 defines module error.e07410.good defines class Toggle on as Boolean? default private Toggle() as pure Toggle() as pure -> initial as Boolean this.on :=? initial //'~' returns the type it is declared on default operator ? operator ~ as pure <- rtn as Toggle: Toggle(not on)
Questions and answers
These Q&A entries show E07410 and its fix: