Created
March 12, 2019 20:15
-
-
Save schmee/28a986e753b46ae8b161df7f71c17f90 to your computer and use it in GitHub Desktop.
inferred union cast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub const Leaf = struct { | |
frequency: u32, | |
value: u8, | |
}; | |
pub const Branch = struct { | |
frequency: u32, | |
left: ?*Node, | |
right: ?*Node, | |
}; | |
pub const Node = union(enum) { | |
Branch: Branch, | |
Leaf: Leaf, | |
}; | |
pub fn main() !void { | |
const node: Node = Node { | |
.Leaf = Leaf { | |
.frequency = 1, | |
.value = 1, | |
} | |
}; | |
const Tag: @TagType(Node) = node; | |
const is_branch = node == Tag.Branch; | |
} | |
➜ git:(master) ✗ zig build-exe asdf.zig && ./asdf | |
asdf.zig:25:34: error: no member named 'Branch' in enum '@TagType(Node)' | |
const is_branch = node == Tag.Branch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment