From 6bd92a21b7f31de913c7383ea380f3b68d387395 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 5 Feb 2025 23:07:43 +0000 Subject: [PATCH] behavior: add test for old bug Resolves: #2289 --- test/behavior/union.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 364a83814a..16ae6e509c 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -2322,3 +2322,19 @@ test "assign global tagged union" { try expect(U.global == .b); try expect(U.global.b == 123456); } + +test "set mutable union by switching on same union" { + const U = union(enum) { + foo, + bar: usize, + }; + + var val: U = .foo; + val = switch (val) { + .foo => .{ .bar = 2 }, + .bar => .foo, + }; + + try expect(val == .bar); + try expect(val.bar == 2); +}