zig
zig copied to clipboard
Switch prongs do not inherit runtime safety of parent block
Zig Version
0.12.0-dev.1835+697b8f7d2
Steps to Reproduce and Observed Behavior
Compile example program with zig build-obj runtime_safety_switch_prong_error.zig
runtime_safety_switch_prong_error.zig:
pub fn panic(_: []const u8, _: @TypeOf(@errorReturnTrace()), _: ?usize) noreturn {
@compileError("");
}
pub export fn entry() usize {
@setRuntimeSafety(false);
var u: usize = 0;
switch (u) {
else => {
// @setRuntimeSafety(false);
u += 1;
},
}
return u;
}
Result:
zig build-obj runtime_safety_switch_prong_error.zig
runtime_safety_switch_prong_error.zig:2:5: error:
@compileError("");
^~~~~~~~~~~~~~~~~
Expected Behavior
Compile example program with zig build-obj runtime_safety_block_correct.zig
runtime_safety_block_correct.zig:
pub fn panic(_: []const u8, _: @TypeOf(@errorReturnTrace()), _: ?usize) noreturn {
@compileError("");
}
pub export fn entry() usize {
@setRuntimeSafety(false);
var u: usize = 0;
{
u += 1;
}
if (true) {
u += 1;
}
while (true) {
u += 1;
}
for (0..1) |_| {
u += 1;
}
return u;
}
Result:
zig build-obj runtime_safety_block_correct.zig
Behaviour should be consistent with other sub-blocks.