diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-02-19 17:47:57 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-02-19 21:18:27 -0700 |
| commit | ffdce5f98c7f3d7e18db933e1fb54f987efd5fbf (patch) | |
| tree | 2b8ce5271e2313947559bfddcf4bd7a034198e19 /test/behavior/struct.zig | |
| parent | 53104b91656182094a4048964f6a3f384e7f199f (diff) | |
| download | zig-ffdce5f98c7f3d7e18db933e1fb54f987efd5fbf.tar.gz zig-ffdce5f98c7f3d7e18db933e1fb54f987efd5fbf.zip | |
add test coverage for fixed bug. closes #5497
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index ed3e1ce88f..8a01d68587 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1578,3 +1578,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); + } +} |
