Hi, I'm learning zig and I've found a confusing error when doing a switch on a pointer to a tagged union.
I need to access the union through a pointer because sometimes I need to mutate one of the inner fields of the union and other times I want to change to a different tag.
I've constructed a somewhat non-sensical example:
const Foo = union(enum) {
a: u8,
b,
};
pub fn main() !void {
var foo: Foo = .b;
while (true) {
switch (&foo) {
.a => |a| {
a.* += 1;
},
.b => {
foo = Foo{ .a = 0 };
},
}
}
}
And then when running:
$ zig run wtf.zig
wtf.zig:10:9: error: else prong required when switching on type '*wtf.Foo'
shell returned 1
Why do I need an else branch on the switch? Is this avoidable?