E07420: returning type must not be same for promotion
What went wrong
A promotion operator (#^) must return a DIFFERENT type than the input type. Promoting to the same type is pointless.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 839 (Why must the promote operator #^ return a different type ...)
Rationale
PROMOTION (#^) converts a type to a broader/different type.
How to fix it
- Return a different (usually broader) type
Common causes
- Mistake in return type
- Misunderstanding promotion purpose
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07420: returning type must not be same for promotion
#!ek9 defines module error.e07420.bad defines class Celsius degrees <- 0.0 //Promotion converts to ANOTHER type default operator ? operator #^ as pure <- rtn as Celsius: this
Fixed: Promote to a different type
#!ek9 defines module error.e07420.good defines class Celsius degrees <- 0.0 default operator ? operator #^ as pure <- rtn as Float: degrees
Questions and answers
These Q&A entries show E07420 and its fix:
Found a problem?
If EK9 reported E07420 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.