Commit 27d4bf7534

amp-59 <114923809+amp-59@users.noreply.github.com>
2023-12-29 12:42:44
Sema: Initialise `want_safety` for switch prong child block
1 parent b0dba46
Changed files (2)
src/Sema.zig
@@ -11806,6 +11806,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
         .runtime_cond = block.runtime_cond,
         .runtime_loop = block.runtime_loop,
         .runtime_index = block.runtime_index,
+        .want_safety = block.want_safety,
         .error_return_trace_index = block.error_return_trace_index,
     };
     const merges = &child_block.label.?.merges;
test/cases/inherit_want_safety.zig
@@ -0,0 +1,30 @@
+pub const panic = @compileError("");
+
+pub export fn entry() usize {
+    @setRuntimeSafety(false);
+    var u: usize = 0;
+    {
+        u += 1;
+    }
+    if (u == 0) {
+        u += 1;
+    }
+    while (u == 0) {
+        u += 1;
+    }
+    for (0..u) |_| {
+        u += 1;
+    }
+    defer {
+        u += 1;
+    }
+    switch (u) {
+        else => {
+            u += 1;
+        },
+    }
+    return u;
+}
+
+// compile
+// output_mode=Obj