Skip to content

Commit

Permalink
Removes dead code, fixes expect order
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonRemaley committed Jan 8, 2025
1 parent 74027a5 commit 0320026
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 57 deletions.
47 changes: 0 additions & 47 deletions src/zon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +91,6 @@ const Ident = struct {
}
};

const FieldTypes = union(enum) {
st: struct {
ty: Type,
loaded: InternPool.LoadedStructType,
},
un: struct {
ty: Type,
loaded: InternPool.LoadedEnumType,
},
none,

fn init(ty: ?Type, sema: *Sema) !@This() {
const t = ty orelse return .none;
const ip = &sema.pt.zcu.intern_pool;
switch (t.zigTypeTagOrPoison(sema.pt.zcu) catch return .none) {
.@"struct" => {
try t.resolveFully(sema.pt);
const loaded_struct_type = ip.loadStructType(t.toIntern());
return .{ .st = .{
.ty = t,
.loaded = loaded_struct_type,
} };
},
.@"union" => {
try t.resolveFully(sema.pt);
const loaded_union_type = ip.loadUnionType(t.toIntern());
const loaded_tag_type = loaded_union_type.loadTagType(ip);
return .{ .un = .{
.ty = t,
.loaded = loaded_tag_type,
} };
},
else => return .none,
}
}

fn get(self: *const @This(), name: NullTerminatedString, zcu: *Zcu) ?Type {
const ip = &zcu.intern_pool;
const self_ty, const index = switch (self.*) {
.st => |st| .{ st.ty, st.loaded.nameIndex(ip, name) orelse return null },
.un => |un| .{ un.ty, un.loaded.nameIndex(ip, name) orelse return null },
.none => return null,
};
return self_ty.fieldType(index, zcu);
}
};

fn lowerExpr(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {
switch (Type.zigTypeTag(res_ty, self.sema.pt.zcu)) {
.bool => return self.lowerBool(node),
Expand Down
20 changes: 10 additions & 10 deletions test/behavior/zon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ test "union" {
const union2: Union = @import("zon/union2.zon");
const union3: Union = @import("zon/union3.zon");

try expectEqual(union1.x, 1.5);
try expectEqual(union2.y, true);
try expectEqual(union3.z, {});
try expectEqual(1.5, union1.x);
try expectEqual(true, union2.y);
try expectEqual({}, union3.z);
}

// Inferred tag
Expand All @@ -50,9 +50,9 @@ test "union" {
const union2: Union = @import("zon/union2.zon");
const union3: Union = @import("zon/union3.zon");

try expectEqual(union1.x, 1.5);
try expectEqual(union2.y, true);
try expectEqual(union3.z, {});
try expectEqual(1.5, union1.x);
try expectEqual(true, union2.y);
try expectEqual({}, union3.z);
}

// Explicit tag
Expand All @@ -72,9 +72,9 @@ test "union" {
const union2: Union = @import("zon/union2.zon");
const union3: Union = @import("zon/union3.zon");

try expectEqual(union1.x, 1.5);
try expectEqual(union2.y, true);
try expectEqual(union3.z, {});
try expectEqual(1.5, union1.x);
try expectEqual(true, union2.y);
try expectEqual({}, union3.z);
}
}

Expand Down Expand Up @@ -387,7 +387,7 @@ test "floats" {
0x1234_5678.9ABC_CDEFp-10,
};
const actual: T = @import("zon/floats.zon");
try expectEqual(actual, expected);
try expectEqual(expected, actual);
}

test "inf and nan" {
Expand Down

0 comments on commit 0320026

Please sign in to comment.