E07395: 'Void' has no accessible methods or operators

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

What went wrong

You applied an operator or method (for example '?') to the result of a call that returns 'Void' - i.e. it returns nothing. 'Void' is the absence of a value, so it has no accessible methods or operators; asking "is this no-value set?" is always false and therefore pointless.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 66 (How does the while loop work?)
  • ek9 -q 74 (How do guard variables work in if statements?)

'process()' returns nothing (Void), so 'if process()?' is meaningless. The [EXAMPLE] section below shows it, then the two fixes: call the function as a statement, or give a function a value to return and test that.

How to fix it

  1. If you only need the side effect, call it as a plain statement: 'process()'
  2. If you need a condition, give the function a returning value ('<- rtn as ...') and test that value instead
  3. Remove the operator/method - there is nothing on a 'Void' result to operate on

Common causes

  • Wrapping a side-effecting (void) call in 'if <call>?' expecting a success flag
  • A guard 'if x <- voidCall()' where the call yields no value
  • Copy/paste from a function that used to return a value but no longer does

See also

  • E07395: operator/method on 'Void' (this error)
  • E07390: constant Boolean in condition (also a pointless condition)

Examples

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

Fails with E07395: 'Void' has no accessible methods or operators

#!ek9
defines module error.e07395.bad

  defines function

    process()
      value <- 1
      require value?

  defines program

    //'process()' returns nothing (Void), so '?' has no meaningful receiver.
    BadIfVoidIsSet()
      stdout <- Stdout()

      if process()?
        stdout.println("never runs")

    //The same pointlessness via an assert condition.
    BadAssertVoidIsSet()
      assert process()?

Fixed: Call it as a statement, or return a value to test

#!ek9
defines module error.e07395.good

  defines function

    process()
      stdout <- Stdout()
      stdout.println("processing")

    countItems()
      <- rtn as Integer: 3

  defines program

    //Option 1: only the side effect is needed, so just call it
    CallIt()
      process()

    //Option 2: return a value, and test that
    TestAValue()
      stdout <- Stdout()
      if count <- countItems()
        stdout.println(`${count} items`)

Found a problem?

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