aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-06 17:31:43 -0800
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-07 07:30:30 -0800
commitc9fac41368c872d424681ea3cf93a9d97157143e (patch)
tree887f6058136580aad6110a329d82038ba71ad663 /test/behavior
parentc7e4c711fc5795e66f974316611922a0b962eb99 (diff)
downloadzig-c9fac41368c872d424681ea3cf93a9d97157143e.tar.gz
zig-c9fac41368c872d424681ea3cf93a9d97157143e.zip
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).
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/pointers.zig8
1 files changed, 8 insertions, 0 deletions
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