aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
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 /test/behavior
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 'test/behavior')
-rw-r--r--test/behavior/struct.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 393f23ec6e..f6fb45f46b 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -995,6 +995,24 @@ test "struct with union field" {
try expect(True.kind.Bool);
}
+test "struct with 0-length union array field" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const U = union {
+ a: u32,
+ b: u64,
+ };
+
+ const S = struct {
+ zero_length: [0]U,
+ };
+
+ var s: S = undefined;
+ try expectEqual(@as(usize, 0), s.zero_length.len);
+}
+
test "type coercion of anon struct literal to struct" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO