From 6fbdc341740424bdb7df7e7abccd4834d0f35b0f Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Wed, 7 Dec 2022 18:00:52 +0100 Subject: [PATCH] behavior: add test coverage for slicing zero length array field of struct Closes #11787 --- lib/std/segmented_list.zig | 5 +---- test/behavior.zig | 1 + test/behavior/bugs/11787.zig | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/behavior/bugs/11787.zig diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index 5e01316572e8..7c0a27b5b797 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -412,10 +412,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type } test "SegmentedList basic usage" { - if (false) { - // https://github.com/ziglang/zig/issues/11787 - try testSegmentedList(0); - } + try testSegmentedList(0); try testSegmentedList(1); try testSegmentedList(2); try testSegmentedList(4); diff --git a/test/behavior.zig b/test/behavior.zig index e4a04bbccb93..404445812e2a 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -81,6 +81,7 @@ test { _ = @import("behavior/bugs/11179.zig"); _ = @import("behavior/bugs/11181.zig"); _ = @import("behavior/bugs/11213.zig"); + _ = @import("behavior/bugs/11787.zig"); _ = @import("behavior/bugs/11816.zig"); _ = @import("behavior/bugs/12003.zig"); _ = @import("behavior/bugs/12025.zig"); diff --git a/test/behavior/bugs/11787.zig b/test/behavior/bugs/11787.zig new file mode 100644 index 000000000000..8678f0789af2 --- /dev/null +++ b/test/behavior/bugs/11787.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const testing = std.testing; + +test "slicing zero length array field of struct" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const S = struct { + a: [0]usize, + fn foo(self: *@This(), start: usize, end: usize) []usize { + return self.a[start..end]; + } + }; + var s: S = undefined; + try testing.expect(s.foo(0, 0).len == 0); +}