Return void; is a compiler error while return; works

This could be wanted behaviour, it could not be, so I’m here for answers.
Also, is it something you think would be useful to the language?
Or something bad?

Edit: To clarify I’ll add example code

pub fn main() void {
      return void;
}
src/main.zig:4:12: error: expected type 'void', found 'type'
    return void;

While with

pub fn main() void {
     return;
}

It compiles.

void is a type. Values of type void do not have content. The type of void is type. The only “instance” of void is {}. You can do return {}; if you want to return from a function which returns void. But void is not an instance of void. You can only return void; if you want to return a type.

return {}; and return; are equivalent.

6 Likes

Yeah I get it now.
The same way you cant do

pub fn main() i32 {
     return i32;
}

Thank you so much!

1 Like