E10010: 'void' return type cannot be used with an assignment

Category: E10xxx IR generation · Reported in phase: FULL_RESOLUTION · Classification: RETURN_TYPE_VOID_MEANINGLESS · All error codes

What went wrong

You're trying to use a VOID function's result in an assignment or expression. Void functions don't return values.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 941 (Why can't I assign the result of a void function in E...)

How to fix it

  1. Add return value to function if needed
  2. Or don't try to capture void result

The [EXAMPLE] section below shows a void function's result held in a variable, and the call made on its own beside a function that does return a value.

Common causes

  • Assigning result of procedure-like function
  • Using void function in expression

See also

  • E10010: void result in assignment (this error)
  • E10020: void in stream pipeline

Examples

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

Fails with E10010: 'void' return type cannot be used with an assignment

#!ek9
defines module error.e10010.bad

  defines function

    logItem()
      -> item as String
      stdout <- Stdout()
      stdout.println(item)

    process()
      outcome <- logItem("first")
      require outcome?

Fixed: Call it as a statement, or give it a returning variable

#!ek9
defines module error.e10010.good

  defines function

    logItem()
      -> item as String
      stdout <- Stdout()
      stdout.println(item)

    describe()
      -> item as String
      <- rtn as String: `item: ${item}`

    process()
      logItem("first")
      outcome <- describe("second")
      logItem(outcome)

Questions and answers

These Q&A entries show E10010 and its fix:

Found a problem?

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