From c9fac41368c872d424681ea3cf93a9d97157143e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 6 Mar 2022 17:31:43 -0800 Subject: stage2: resolve array type for typed array init expressions Array types with sentinels were not being typed correctly in the translation from ZIR to Sema (comptime). This modifies the `array_init` ZIR to also retain the type of the init expression (note: untyped array initialization is done via the `array_init_anon` ZIR and so is unchanged in this commit). --- test/behavior/pointers.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/behavior/pointers.zig') diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 6fd7e41a6d..d2ec6d9bbc 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -270,6 +270,14 @@ test "assign null directly to C pointer and test null equality" { comptime try expect((y1 orelse &othery) == y1); } +test "array initialization types" { + const E = enum { A, B, C }; + try expect(@TypeOf([_]u8{}) == [0]u8); + try expect(@TypeOf([_:0]u8{}) == [0:0]u8); + try expect(@TypeOf([_:.A]E{}) == [0:.A]E); + try expect(@TypeOf([_:0]u8{ 1, 2, 3 }) == [3:0]u8); +} + test "null terminated pointer" { if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO -- cgit v1.2.3