-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support tagged unions #5
Labels
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
Milestone
Comments
Proposal: enum Foo {
One {
x: i32,
},
Two {
x: u64,
y: u64,
},
Three,
}
enum Bar {
A = 0,
B = 2,
C = 4,
D = 8,
}
fn f() {
const foo = Foo::One { .x = 1234, };
const bar = Bar::A;
if (#enum_count(Foo) != 3) {
unreachable;
}
if (#enum_count(Bar) != 4) {
unreachable;
}
if (#sizeof(Foo) != 17) {
unreachable;
}
if (#sizeof(Bar) != 1) {
unreachable;
}
} |
New plan: struct Point {
x: u64,
y: u64,
}
enum Foo {
One: i32,
Two: Point,
Three: void,
}
enum Bar {
A,
B,
C,
D,
}
fn f(foo: Foo) -> void {
switch (foo) {
one(x) {
},
two(point) {
},
three {
},
}
}
fn f() {
const foo1 = Foo.One(13);
const foo2 = Foo.Two(Point { .x = 1234, .y = 5678, });
const bar = Bar.A;
if (#enum_count(Foo) != 3) {
unreachable;
}
if (#enum_count(Bar) != 4) {
unreachable;
}
if (#sizeof(Foo) != 17) {
unreachable;
}
if (#sizeof(Bar) != 1) {
unreachable;
}
} No longer allowed to assign to enum values. They're always ordered with 0 as the first one, N - 1 as the last one, and |
andrewrk
added a commit
that referenced
this issue
Apr 20, 2016
andrewrk
added a commit
that referenced
this issue
Apr 20, 2016
andrewrk
added a commit
that referenced
this issue
Apr 20, 2016
Closed
gonzus
added a commit
to gonzus/zig
that referenced
this issue
May 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
void
(or left unspecified) codegen to a simple unsigned integer with the smallest bit width possible.#enum_count(...)
Foo.One { Point { .x = 1, .y = 2,} }
The text was updated successfully, but these errors were encountered: