-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
langref: improve zero bit types documentation #14385
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty enums and unions are not zero-bit types but noreturn types. Their behavior is a bit buggy currently though #13807.
The following executable: const std = @import("std");
const debug = std.debug;
pub fn main() void {
inline for (.{
enum {},
union {},
}) |typ| {
debug.print("typ: {}\n", .{typ});
debug.print("@typeInfo(typ): {}\n", .{@typeInfo(typ)});
}
} prints:
Thanks. |
I also tried the examples in #13807, with zig 0.11.0-dev.1327+b42bd759a. The empty What about adding the empty P.S.: How can the compiler change the way it recognizes empty enums and unions? |
An empty error set is also a noreturn type, not a zero-bit type.
Noreturn types affect the semantic analysis and empty enums and unions currently behave incorrectly because I'm unsure what the proper behavior should be. |
Why not just disallow empty struct, empty union and empty enum? |
See #3257 |
4946b96
to
e82feab
Compare
I removed the empty struct, enum and union from the list and updated the commit message. At the end of the section I added a clarification about problematic empty types. |
In the Zero Bit Types section, clarify that a non empty zero bit union just needs to have all fields of zero bit type, instead of only one field of zero bit type. Clarify that empty struct, enum, union and error set are currently problematic.
e82feab
to
99f2734
Compare
In the Zero Bit Types section, add the empty enum, empty struct and empty union. Clarify that a non empty zero bit union just needs to have all fields of zero bit type, instead of only one field of zero bit type.
Add a doctest.