| ... | @@ -1578,3 +1578,38 @@ test "directly initiating tuple like struct" { | ... | @@ -1578,3 +1578,38 @@ test "directly initiating tuple like struct" { |
| 1578 | const a = struct { u8 }{8}; | 1578 | const a = struct { u8 }{8}; |
| 1579 | try expect(a[0] == 8); | 1579 | try expect(a[0] == 8); |
| 1580 | } | 1580 | } |
| | 1581 | |
| | 1582 | test "instantiate struct with comptime field" { |
| | 1583 | { |
| | 1584 | var things = struct { |
| | 1585 | comptime foo: i8 = 1, |
| | 1586 | }{}; |
| | 1587 | |
| | 1588 | comptime std.debug.assert(things.foo == 1); |
| | 1589 | } |
| | 1590 | |
| | 1591 | { |
| | 1592 | const T = struct { |
| | 1593 | comptime foo: i8 = 1, |
| | 1594 | }; |
| | 1595 | var things = T{}; |
| | 1596 | |
| | 1597 | comptime std.debug.assert(things.foo == 1); |
| | 1598 | } |
| | 1599 | |
| | 1600 | { |
| | 1601 | var things: struct { |
| | 1602 | comptime foo: i8 = 1, |
| | 1603 | } = .{}; |
| | 1604 | |
| | 1605 | comptime std.debug.assert(things.foo == 1); |
| | 1606 | } |
| | 1607 | |
| | 1608 | { |
| | 1609 | var things: struct { |
| | 1610 | comptime foo: i8 = 1, |
| | 1611 | } = undefined; // Segmentation fault at address 0x0 |
| | 1612 | |
| | 1613 | comptime std.debug.assert(things.foo == 1); |
| | 1614 | } |
| | 1615 | } |