E07590: if a program returns a value it can only be an Integer
What went wrong
A program's return value (exit code) must be Integer, but you're returning a different type.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 888 (Why can EK9 programs only return Integer?)
- ek9 -q 1431 (How does an EK9 program set its exit status?)
Exit code conventions
- 0: Success
- 1: General error
- 2: Command line usage error
- Non-zero: Failure
[HOW A PROGRAM'S EXIT STATUS IS DECIDED]
- It finishes normally: 0.
- It returns an Integer: that value (an unset return exits 1).
- An Exception nothing catches: its own exit code, else 1 (Exception("Settings missing", 3) exits 3).
- A Panic (failed require, constrained-type breach): always 1.
There is no exit() call. These share their numbers with the ek9 command's own exit codes (8 = compilation failed, ...); see ek9 -q 1437.
How to fix it
- Change return type to Integer
- Return appropriate exit code
- If the value was meant to explain a failure, print it on stderr and return a non-zero Integer, or throw an Exception carrying the exit code
Common causes
- Wrong return type on program
- Returning message String instead of exit code
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07590: if a program returns a value it can only be an Integer
#!ek9 defines module error.e07590.bad defines record ATestRecord first <- "A" second <- 9 defines record LaterRecord name <- "later" defines function validIntegerReturn() <- rtn <- 1 validFloatReturn() <- rtn <- 4.56 validTimeReturn() <- rtn <- 12:23:15 validDateReturn() <- rtn <- 2023-02-24 validDateTimeReturn() <- rtn <- 2023-02-24T15:48:21Z //Two weeks validDurationReturn() <- rtn <- P2W validMillisecondReturn() <- rtn <- 202ms validBitsReturn() <- rtn <- 0b010110 validMoneyReturn() <- rtn <- 330.26#GBP validColourReturn() <- rtn <- #CC04FADD validDimensionReturn() <- rtn <- 23.5km validPathReturn() <- rtn <- $?.some.path.inc[0].array validRegexReturn() <- rtn <- /[a-zA-Z0-9]{6}/ defines program //Failure 1 - cannot return anything other than an Integer BadReturnType1() <- rtn as Float: 0.9 //Just some body to stop any other compiler errors v <- "Steve" require v? //Failure 2 - but mainValue not set on BadReturnType2() <- rtn as Float? rtn: 5.6 //Failure 3 - simple type inference - but still not allowed type BadReturnType3() <- rtn <- false //Just some body to stop any other compiler errors v <- "Steve" require v? //Failure 4 - a specific developer created type BadReturnType4() <- rtn as ATestRecord? //Just some body to stop any other compiler errors v <- "Steve" require v? //Failure 5 - a record declared LATER in the file; not resolvable in SYMBOL_DEFINITION (front-end audit FE37) BadReturnType5() <- rtn as LaterRecord? //Just some body to stop any other compiler errors v <- "Steve" require v? ValidProgramNoReturn() v <- "Steve" require v? ValidProgramIntegerReturn1() <- rtn as Integer: 0 //Just some body to stop any other compiler errors v <- "Steve" require v? //Valid with type inference and shorthand return notation. ValidProgramIntegerReturn2() <- rtn <- 0 //Just some body to stop any other compiler errors v <- "Steve" require v? //Valid - an Integer inferred from a constructor call. Rejected with a false E07590 while this check ran in //SYMBOL_DEFINITION, where an inferred returning param has no type yet (front-end audit FE37). ValidProgramIntegerReturn3() <- rtn <- Integer(3) //Just some body to stop any other compiler errors v <- "Steve" require v?
Fixed: Return an Integer exit code, or nothing
#!ek9 defines module error.e07590.good defines program //The only value a program can return is its Integer exit code Check() <- rtn as Integer: 0 stdout <- Stdout() stdout.println("checked")
Questions and answers
These Q&A entries show E07590 and its fix: