E07406: returning block is not required as there is no 'lhs' variable to assign it to

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

What went wrong

You've added a returning block (<- ...) to a control structure, but you're not using it in an assignment. The return value would be lost.

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. Capture the result in an assignment
  2. Or remove returning block for statement form

Common causes

  • Statement with return that's not captured
  • Refactoring left orphaned return

See also

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

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07406: returning block is not required as there is no 'lhs' variable to assign it to

#!ek9
defines module error.e07406.bad

  defines function

    describe()
      -> word as String
      <- rtn as String: String()

      //Nothing receives the switch's value
      switch word
        <- text as String: String()
        case "ToCheck"
          rtn: "Jackpot"
        default
          rtn: "Nothing"

Fixed: Remove the returning declaration from a switch statement

#!ek9
defines module error.e07406.good

  defines function

    describe()
      -> word as String
      <- rtn as String: String()

      //A switch statement: no returning variable
      switch word
        case "ToCheck"
          rtn: "Jackpot"
        default
          rtn: "Nothing"

Questions and answers

These Q&A entries show E07406 and its fix:

Found a problem?

If EK9 reported E07406 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.