aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/eval.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-24 17:45:34 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-24 17:47:39 -0700
commit5c68afef94b0b80823e033bd6965fcda74e19ebe (patch)
treee66fb82c14c731edce688b50150ccc38b585b729 /test/behavior/eval.zig
parent9a1d5001d4bf1f28bd0f23e8b936d677e0e5aac8 (diff)
downloadzig-5c68afef94b0b80823e033bd6965fcda74e19ebe.tar.gz
zig-5c68afef94b0b80823e033bd6965fcda74e19ebe.zip
AstGen: fix const locals with comptime initializations
`const foo = comptime ...` generated invalid ZIR when the initialization expression contained an array literal because the validate_array_init_comptime instruction assumed that the corresponding alloc instruction was comptime. The solution is to look slightly ahead and notice that the initialization expression would be comptime-known and affect the alloc instruction tag accordingly.
Diffstat (limited to 'test/behavior/eval.zig')
-rw-r--r--test/behavior/eval.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig
index 2129512f96..0328111daa 100644
--- a/test/behavior/eval.zig
+++ b/test/behavior/eval.zig
@@ -859,3 +859,22 @@ test "debug variable type resolved through indirect zero-bit types" {
const slice: []const T = &[_]T{};
_ = slice;
}
+
+test "const local with comptime init through array init" {
+ const E1 = enum {
+ A,
+ fn a() void {}
+ };
+
+ const S = struct {
+ fn declarations(comptime T: type) []const std.builtin.Type.Declaration {
+ return @typeInfo(T).Enum.decls;
+ }
+ };
+
+ const decls = comptime [_][]const std.builtin.Type.Declaration{
+ S.declarations(E1),
+ };
+
+ try comptime expect(decls[0][0].name[0] == 'a');
+}