Commit 5093a5cd19

mlugg <mlugg@mlugg.co.uk>
2024-07-16 20:35:31
std.Zir: some declaration traversal fixes
1 parent ee695c8
Changed files (1)
lib
std
lib/std/zig/Zir.zig
@@ -3791,11 +3791,15 @@ fn findDeclsSwitch(
         break :blk multi_cases_len;
     } else 0;
 
+    if (extra.data.bits.any_has_tag_capture) {
+        extra_index += 1;
+    }
+
     const special_prong = extra.data.bits.specialProng();
     if (special_prong != .none) {
-        const body_len: u31 = @truncate(zir.extra[extra_index]);
+        const prong_info: Inst.SwitchBlock.ProngInfo = @bitCast(zir.extra[extra_index]);
         extra_index += 1;
-        const body = zir.bodySlice(extra_index, body_len);
+        const body = zir.bodySlice(extra_index, prong_info.body_len);
         extra_index += body.len;
 
         try zir.findDeclsBody(list, body);
@@ -3805,10 +3809,10 @@ fn findDeclsSwitch(
         const scalar_cases_len = extra.data.bits.scalar_cases_len;
         for (0..scalar_cases_len) |_| {
             extra_index += 1;
-            const body_len: u31 = @truncate(zir.extra[extra_index]);
+            const prong_info: Inst.SwitchBlock.ProngInfo = @bitCast(zir.extra[extra_index]);
             extra_index += 1;
-            const body = zir.bodySlice(extra_index, body_len);
-            extra_index += body_len;
+            const body = zir.bodySlice(extra_index, prong_info.body_len);
+            extra_index += body.len;
 
             try zir.findDeclsBody(list, body);
         }
@@ -3819,20 +3823,13 @@ fn findDeclsSwitch(
             extra_index += 1;
             const ranges_len = zir.extra[extra_index];
             extra_index += 1;
-            const body_len: u31 = @truncate(zir.extra[extra_index]);
+            const prong_info: Inst.SwitchBlock.ProngInfo = @bitCast(zir.extra[extra_index]);
             extra_index += 1;
-            const items = zir.refSlice(extra_index, items_len);
-            extra_index += items_len;
-            _ = items;
 
-            var range_i: usize = 0;
-            while (range_i < ranges_len) : (range_i += 1) {
-                extra_index += 1;
-                extra_index += 1;
-            }
+            extra_index += items_len + ranges_len * 2;
 
-            const body = zir.bodySlice(extra_index, body_len);
-            extra_index += body_len;
+            const body = zir.bodySlice(extra_index, prong_info.body_len);
+            extra_index += body.len;
 
             try zir.findDeclsBody(list, body);
         }