zig icon indicating copy to clipboard operation
zig copied to clipboard

error: else prong required when switching on type 'void'

Open pfgithub opened this issue 2 months ago • 2 comments

Zig Version

0.16.0-dev.747+493ad58ff

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    switch({}) {
        {} => {},
    }
}

zig run a.zig

a.zig:2:5: error: else prong required when switching on type 'void'
    switch({}) {
    ^~~~~~

Expected Behavior

There should be no error because all cases are handled

pfgithub avatar Oct 20 '25 21:10 pfgithub

But why switch on type void in the first place ? Wouldn't it be better to use an enum with no fields ?

EtienneParmentier avatar Nov 03 '25 13:11 EtienneParmentier

an enum with no fields is uninstantiable. but i do agree that without a clearer use case explanation switching on void should be a compile error outright.

nektro avatar Nov 03 '25 22:11 nektro