| ... | @@ -549,3 +549,21 @@ test "initialize global array of union" { | ... | @@ -549,3 +549,21 @@ test "initialize global array of union" { |
| 549 | expect(glbl_array[0].U0 == 1); | 549 | expect(glbl_array[0].U0 == 1); |
| 550 | expect(glbl_array[1].U1 == 2); | 550 | expect(glbl_array[1].U1 == 2); |
| 551 | } | 551 | } |
| | 552 | |
| | 553 | test "anonymous union literal syntax" { |
| | 554 | const S = struct { |
| | 555 | const Number = union { |
| | 556 | int: i32, |
| | 557 | float: f64, |
| | 558 | }; |
| | 559 | |
| | 560 | fn doTheTest() void { |
| | 561 | var i: Number = .{.int = 42}; |
| | 562 | var f: Number = .{.float = 12.34}; |
| | 563 | expect(i.int == 42); |
| | 564 | expect(f.float == 12.34); |
| | 565 | } |
| | 566 | }; |
| | 567 | S.doTheTest(); |
| | 568 | comptime S.doTheTest(); |
| | 569 | } |