fix: release mode undefined usage (for optionals); bump to 0.14.dev
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 54s

This commit is contained in:
2024-11-19 23:27:12 +01:00
parent f4adf53067
commit 6cd78d0418
16 changed files with 206 additions and 71 deletions

View File

@@ -23,12 +23,12 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
if (!isTaggedUnion(A) or !isTaggedUnion(B)) {
@compileError("Both types for merging tagged unions need to be of type `union(enum)`.");
}
const a_fields = @typeInfo(A).Union.fields;
const a_fields_tag = @typeInfo(A).Union.tag_type.?;
const a_enum_fields = @typeInfo(a_fields_tag).Enum.fields;
const b_fields = @typeInfo(B).Union.fields;
const b_fields_tag = @typeInfo(B).Union.tag_type.?;
const b_enum_fields = @typeInfo(b_fields_tag).Enum.fields;
const a_fields = @typeInfo(A).@"union".fields;
const a_fields_tag = @typeInfo(A).@"union".tag_type.?;
const a_enum_fields = @typeInfo(a_fields_tag).@"enum".fields;
const b_fields = @typeInfo(B).@"union".fields;
const b_fields_tag = @typeInfo(B).@"union".tag_type.?;
const b_enum_fields = @typeInfo(b_fields_tag).@"enum".fields;
var fields: [a_fields.len + b_fields.len]std.builtin.Type.UnionField = undefined;
var enum_fields: [a_fields.len + b_fields.len]std.builtin.Type.EnumField = undefined;
var i: usize = 0;
@@ -49,19 +49,19 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
const log2_i = @bitSizeOf(@TypeOf(i)) - @clz(i);
const EventType = @Type(.{ .Int = .{
const EventType = @Type(.{ .int = .{
.signedness = .unsigned,
.bits = log2_i,
} });
const Event = @Type(.{ .Enum = .{
const Event = @Type(.{ .@"enum" = .{
.tag_type = EventType,
.fields = enum_fields[0..],
.decls = &.{},
.is_exhaustive = true,
} });
return @Type(.{ .Union = .{
return @Type(.{ .@"union" = .{
.layout = .auto,
.tag_type = Event,
.fields = fields[0..],
@@ -72,7 +72,7 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
// Determine at `comptime` whether the provided type `E` is an `union(enum)`.
pub fn isTaggedUnion(comptime E: type) bool {
switch (@typeInfo(E)) {
.Union => |u| {
.@"union" => |u| {
if (u.tag_type) |_| {} else {
return false;
}