You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, the example there only gives an error when running zig test test.zig, which I'd say it's a run-time Detectable illegal behaviour. For non-exhaustive swithing to be a true compile-time error, I'd expect "zig build-exe test.zig" to detect the error (without running the test. Notice, I just changed the test to a fn definition).
test.zig
const Color = enum {
auto,
off,
on,
};
// test "exhaustive switching" {
fn nonExhanstiveSwitch() struct{} {
const color = Color.off;
switch (color) {
Color.auto => {},
Color.on => {},
}
}
Other places I found where zig doc is vague w.r.t compile-time vs. run-time (including test-time) are const/immutable usage check. The initiution from other languages, I'd expect they are true compile-time check without writing/running any tests.
Am I misunderstanding some fundamental principal of zig here, or this is just a tranisent state before zig reaches 1.0?
Thanks!
The text was updated successfully, but these errors were encountered:
Zig has lazy top level declaration analysis, which means that if a function is not called, or otherwise used, it is not analyzed. This means that there may be an undiscovered compile error in a function because it is never called.
I'm still wondering why? compiler speed? dead code elimination? or some other reasons.
If these are just trade-offs, is there (or should there be) a build mode that prefer compile-time correctness as well?
The primary reason for this is that Zig doesn't have a preprocessor. This is the replacement feature that allows one library to have code supporting multiple operating systems, without causing problems when values are undefined. As long as you don't call the windows functions when compiling for linux, they won't get compiled, and you won't get errors about missing functions.
Hi, just started learning zig, and like the design very much!
One thing I'm a little puzzled, what is the difference between Compile-time error VS. (Run-time) Detectable illegal behaviour.
For example https://ziglang.org/documentation/master/#Exhaustive-Switching seems saying "Non-exhaustive Switching is a compile error".
However, the example there only gives an error when running zig test test.zig, which I'd say it's a run-time Detectable illegal behaviour. For non-exhaustive swithing to be a true compile-time error, I'd expect "zig build-exe test.zig" to detect the error (without running the test. Notice, I just changed the test to a fn definition).
test.zig
Other places I found where zig doc is vague w.r.t compile-time vs. run-time (including test-time) are const/immutable usage check. The initiution from other languages, I'd expect they are true compile-time check without writing/running any tests.
Am I misunderstanding some fundamental principal of zig here, or this is just a tranisent state before zig reaches 1.0?
Thanks!
The text was updated successfully, but these errors were encountered: