mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
parent
b21becb2a6
commit
6bd92a21b7
1 changed files with 16 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue