diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-02-27 14:11:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-02-27 16:10:48 -0700 |
| commit | d399f8a489dd2ae62fae9b805778bfdc697a969b (patch) | |
| tree | 60df6836102786a1e665dfc92d815a27d6f8c352 /test/behavior/struct.zig | |
| parent | b5b634e4e8a2a1fe32fba50ccd175257b4213936 (diff) | |
| parent | f6c934677315665c140151b8dd28a56f948205e2 (diff) | |
| download | zig-d399f8a489dd2ae62fae9b805778bfdc697a969b.tar.gz zig-d399f8a489dd2ae62fae9b805778bfdc697a969b.zip | |
Merge remote-tracking branch 'origin/master' into llvm16
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index ed3e1ce88f..348e269682 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1330,7 +1330,6 @@ test "struct field init value is size of the struct" { } test "under-aligned struct field" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO @@ -1578,3 +1577,38 @@ test "directly initiating tuple like struct" { const a = struct { u8 }{8}; try expect(a[0] == 8); } + +test "instantiate struct with comptime field" { + { + var things = struct { + comptime foo: i8 = 1, + }{}; + + comptime std.debug.assert(things.foo == 1); + } + + { + const T = struct { + comptime foo: i8 = 1, + }; + var things = T{}; + + comptime std.debug.assert(things.foo == 1); + } + + { + var things: struct { + comptime foo: i8 = 1, + } = .{}; + + comptime std.debug.assert(things.foo == 1); + } + + { + var things: struct { + comptime foo: i8 = 1, + } = undefined; // Segmentation fault at address 0x0 + + comptime std.debug.assert(things.foo == 1); + } +} |
