E07395: 'Void' has no accessible methods or operators
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:
'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
- If you only need the side effect, call it as a plain statement: 'process()'
- If you need a condition, give the function a returning value ('<- rtn as ...') and test that value instead
- 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
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.