#Inverse of @compileError

1 messages · Page 1 of 1 (latest)

dense dust
#

Is there a zig way to cause a compile error if a code path isn't evaluated? I have a use case where a specific function must be called and was just spitballing about how to make sure I don't make a mistake and forget.

Of it were a comptime if or switch I could leave the else/default as a @compileError, but more generally I assume there's no option for a function?

deft pivot
#

Is there a zig way to cause a compile error if a code path isn't evaluated?
no, by the nature of not being evaluated nothing you put in it will be checked

velvet saddle
#

You can use comptime to set a bool, I guess.ts const std = @import("std"); pub fn main() void { comptime var important_thing_done = false; if (true) { std.debug.print("Doing the important thing\n", .{}); important_thing_done = true; } else { std.debug.print("Not doing the important thing\n", .{}); } if (!important_thing_done) { @compileError("The important thing wasn't done."); } std.debug.print("Hello\n", .{}); }Change the if (true) to if (false) and you get a compile error saying the important thing wasn't done.