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).
This commit is contained in:
Mitchell Hashimoto
2022-03-06 17:31:43 -08:00
parent c7e4c711fc
commit c9fac41368
3 changed files with 39 additions and 16 deletions

View File

@@ -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