1#todo "passes, but prints errors"
2#skip x86_64-linux-none-baseline-whole-selfhosted-new-nopic
3#skip x86_64-linux-none-baseline-whole-selfhosted-new-pic
4#skip x86_64-linux-none-baseline-incremental-selfhosted-new-nopic
5#skip x86_64-linux-none-baseline-incremental-selfhosted-new-pic
6
7#exe {
8--name unions
9-Mroot=unions.zig
10#}
11
12#write unions.zig {
13const Unions = struct {
14 const Enum = enum { first, second, third };
15 const Untagged = extern union {
16 u32: u32,
17 i32: i32,
18 f32: f32,
19 };
20 const SafetyTagged = union {
21 void: void,
22 en: Enum,
23 eu: error{Error}!Enum,
24 };
25 const Tagged = union(enum) {
26 void: void,
27 en: Enum,
28 eu: error{Error}!Enum,
29 };
30
31 untagged: Untagged = .{ .f32 = -1.5 },
32 safety_tagged: SafetyTagged = .{ .en = .second },
33 tagged: Tagged = .{ .eu = error.Error },
34};
35fn testUnions(unions: Unions) void {
36 _ = unions;
37}
38pub fn main() void {
39 testUnions(.{});
40}
41#}
42#update
43#check lldb {
44(lldb) breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'
45Breakpoint 1: where = unions`unions.testUnions + #... at unions.zig:25:1, address = 0x#...
46(lldb) process launch
47Process #... launched: '#.../unions' (#...)
48Process #... stopped
49* thread #1, name = 'unions', stop reason = breakpoint 1.1
50 frame #0: unions`unions.testUnions(unions=Unions @ 0x#...) at unions.zig:25:1
51(lldb) expression --show-types -- Unions
52(type) $0 = struct {
53 (type) Untagged = union {}
54 (type) SafetyTagged = union(enum) {
55 (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) void = .void
56 (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) en = .en
57 (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) eu = .eu
58 }
59 (type) Enum = enum {
60 (root.unions.Unions.Enum) first = .first
61 (root.unions.Unions.Enum) second = .second
62 (root.unions.Unions.Enum) third = .third
63 }
64 (type) Tagged = union(enum) {
65 (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) void = .void
66 (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) en = .en
67 (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu
68 }
69}
70(lldb) frame variable --show-all-children --show-types -- unions
71(root.unions.Unions) unions = {
72 (root.unions.Unions.Untagged) .untagged = {
73 (u32) .u32 = 3217031168
74 (i32) .i32 = -1077936128
75 (f32) .f32 = -1.5
76 }
77 (root.unions.Unions.SafetyTagged) .safety_tagged = {
78 (root.unions.Unions.Enum) .en = .second
79 }
80 (root.unions.Unions.Tagged) .tagged = {
81 (error{Error}!root.unions.Unions.Enum) .eu = {
82 (error{Error}) .error = error.Error
83 }
84 }
85}
86(lldb) breakpoint delete --force 1
871 breakpoints deleted; 0 breakpoint locations disabled.
88#}