E07405: returning block required for assignment to 'lhs' when used in expression

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: RETURNING_REQUIRED · All error codes

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

  1. Add returning block (<-) to produce value

Common causes

  • Using expression form without return declaration
  • Forgot to add returning section

See also

  • E07405: expression without return (this error)
  • E07406: statement with orphaned return

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: 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: