aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorkcbanner <kcbanner@gmail.com>2023-09-24 18:38:14 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-09-25 05:24:55 -0700
commite7bf143b364f004a76e86cad5fd3256fa87761e4 (patch)
tree2732efe1bc7912c7ef10578213e2d529318bedcd /src/type.zig
parent8fab4f98c4ee511ba56fec2f38e2d80535c327a9 (diff)
downloadzig-e7bf143b364f004a76e86cad5fd3256fa87761e4.tar.gz
zig-e7bf143b364f004a76e86cad5fd3256fa87761e4.zip
type: handle the 0-length array case in abiSizeAdvanced
This fixes a panic in `unionAbiSize` when a 0-length array of a union is used as a struct field. Because `resolveTypeLayout` does not resolve the `elem_ty` if `arrayLenIncludingSentinel` returns 0 for the array, the child union type is not guaranteed to have a resolved layout at this point. Fixed this case by just returning 0 here.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index ee0b19d099..88a3a7cc43 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -1244,6 +1244,7 @@ pub const Type = struct {
.array_type => |array_type| {
const len = array_type.len + @intFromBool(array_type.sentinel != .none);
+ if (len == 0) return .{ .scalar = 0 };
switch (try array_type.child.toType().abiSizeAdvanced(mod, strat)) {
.scalar => |elem_size| return .{ .scalar = len * elem_size },
.val => switch (strat) {