From b4ad3e71af77b2be4467d67b64c721adfe86ac17 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 11 Nov 2019 11:14:45 -0500 Subject: [PATCH] add behavior test case for anon union literal --- test/stage1/behavior/union.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index 497aa7e574..de98a26d55 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -549,3 +549,21 @@ test "initialize global array of union" { expect(glbl_array[0].U0 == 1); expect(glbl_array[1].U1 == 2); } + +test "anonymous union literal syntax" { + const S = struct { + const Number = union { + int: i32, + float: f64, + }; + + fn doTheTest() void { + var i: Number = .{.int = 42}; + var f: Number = .{.float = 12.34}; + expect(i.int == 42); + expect(f.float == 12.34); + } + }; + S.doTheTest(); + comptime S.doTheTest(); +}