| ... | ... | @@ -173,3 +173,20 @@ const ZeroBits = union { |
| 173 | 173 | test "union with only 1 field which is void should be zero bits" { |
| 174 | 174 | comptime assert(@sizeOf(ZeroBits) == 0); |
| 175 | 175 | } |
| 176 | |
| 177 | const TheTag = enum {A, B, C}; |
| 178 | const TheUnion = union(TheTag) { A: i32, B: i32, C: i32 }; |
| 179 | test "union field access gives the enum values" { |
| 180 | assert(TheUnion.A == TheTag.A); |
| 181 | assert(TheUnion.B == TheTag.B); |
| 182 | assert(TheUnion.C == TheTag.C); |
| 183 | } |
| 184 | |
| 185 | test "cast union to tag type of union" { |
| 186 | testCastUnionToTagType(TheUnion {.B = 1234}); |
| 187 | comptime testCastUnionToTagType(TheUnion {.B = 1234}); |
| 188 | } |
| 189 | |
| 190 | fn testCastUnionToTagType(x: &const TheUnion) { |
| 191 | assert(TheTag(*x) == TheTag.B); |
| 192 | } |