E07405: returning block required for assignment to 'lhs' when used in expression
What went wrong
You're using a control structure (if/switch/while/for/try) in an ASSIGNMENT context (capturing its result), but no returning block is provided to produce a value.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 782 (When does a switch need a returning block in EK9?)
How to fix it
- Add returning block (<-) to produce value
Common causes
- Using expression form without return declaration
- Forgot to add returning section
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07405: returning block required for assignment to 'lhs' when used in expression
#!ek9 defines module error.e07405.bad defines function describe() -> word as String stdout <- Stdout() //A switch assigned to a variable must declare what it returns description <- switch word case "ToCheck" stdout.println("Jackpot") default stdout.println("Nothing")
Fixed: A switch that returns nothing is a plain switch statement: do not assign it to a variable
#!ek9 defines module error.e07405.good.fix defines function describe() -> word as String stdout <- Stdout() //A switch assigned to a variable must declare what it returns switch word case "ToCheck" stdout.println("Jackpot") default stdout.println("Nothing")
Fixed: Declare the returning variable inside the switch
#!ek9 defines module error.e07405.good defines function describe() -> word as String <- rtn as String: String() description <- switch word <- text as String: String() case "ToCheck" text: "Jackpot" default text: "Nothing" rtn: description
Questions and answers
These Q&A entries show E07405 and its fix:
Found a problem?
If EK9 reported E07405 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.