What does "it is no longer possible to reify error sets" mean?

The Zig 0.16.0 release notes say:

There is no @ErrorSet builtin. To simplify the language, it is no longer possible to reify error sets. Instead, declare your error sets explicitly using error{ … } syntax.

That makes me think I can’t return an error from a function without declaring it in an error set first, e.g. putting return BogusError; in a function without declaring BogusError somewhere should fail. However, that doesn’t appear to be the case…

const std = @import("std");

pub fn main() !void {
	return error.MadeUpStuff;
}
quin@Minix~$ zig build-exe test.zig                                                                                     

quin@Minix~$ ./test                                                                                                     

error: MadeUpStuff                                                                                                      

/home/quin/test.zig:4:2: 0x11d39fc in main (test.zig)                                                                   

return error.MadeUpStuff;                                                                                       

^                                                                                                                      

Same behavior with 0.16.0 and 0.17.0-dev.607+456b2ec07. Am I missing something here?

1 Like

There used to be a built-in, @Type, that let you create types at comptime including errorsets from comptime known string arrays. However, it was replaced with @struct, @union, @enum, etc builtins. But there is no @errorset. So you can’t reify errorsets like that anymore.

You can still

const MyErrors = error{
    MissingThing,
    BadStuff,
};

There is still a hack that let’s you build errorsets from strings, but its not intended.

4 Likes

Oh, so reify in this context doesn’t mean the implicit error behavior? It said to simplify the language, so I assumed it was actually a language change, not just removing a builtin. If you just can’t build errors from strings anymore though that makes sense.

builtins are part of the language, they’re not defined in the stdlib and they’re not functions (even though they do look like functions). as an example @ptrCast can observe the type of the variable it’s being assigned to, something that you cannot do in a zig function.

1 Like

Touche, makes sense.

1 Like