Skip to content

Commit 33cb7af

Browse files
author
Felix "xq" Queißner
committed
Adds missing isize support.
1 parent ccdf860 commit 33cb7af

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

s2s.zig

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,12 @@ fn computeTypeHashInternal(hasher: *TypeHashFn, comptime T: type) void {
567567
}
568568
},
569569
.Enum => |list| {
570-
const Tag = if (list.tag_type == usize) u64 else list.tag_type;
570+
const Tag = if (list.tag_type == usize)
571+
u64
572+
else if (list.tag_type == isize)
573+
i64
574+
else
575+
list.tag_type;
571576
if (list.is_exhaustive) {
572577
// Exhaustive enums only allow certain values, so we
573578
// tag them via the value type
@@ -651,6 +656,8 @@ test "type hasher basics" {
651656
testSameHash(enum(u8) { a, b, c }, enum(u8) { a, b, c });
652657
testSameHash(enum(u8) { a, b, c, _ }, enum(u8) { c, b, a, _ });
653658
testSameHash(enum(u8) { a = 1, b = 6, c = 9 }, enum(u8) { a = 1, b = 6, c = 9 });
659+
testSameHash(enum(usize) { a, b, c }, enum(u64) { a, b, c });
660+
testSameHash(enum(isize) { a, b, c }, enum(i64) { a, b, c });
654661
testSameHash([5]std.meta.Vector(4, u32), [5]std.meta.Vector(4, u32));
655662

656663
testSameHash(union(enum) { a: u32, b: f32 }, union(enum) { a: u32, b: f32 });
@@ -695,6 +702,14 @@ test "serialize basics" {
695702
try testSerialize(enum(u8) { a, b, c }, .b);
696703
try testSerialize(enum(u8) { a, b, c }, .c);
697704

705+
try testSerialize(enum(isize) { a, b, c }, .a);
706+
try testSerialize(enum(isize) { a, b, c }, .b);
707+
try testSerialize(enum(isize) { a, b, c }, .c);
708+
709+
try testSerialize(enum(usize) { a, b, c }, .a);
710+
try testSerialize(enum(usize) { a, b, c }, .b);
711+
try testSerialize(enum(usize) { a, b, c }, .c);
712+
698713
const TestEnum = enum(u8) { a, b, c, _ };
699714
try testSerialize(TestEnum, .a);
700715
try testSerialize(TestEnum, .b);
@@ -784,6 +799,14 @@ test "ser/des" {
784799
try testSerDesAlloc(enum(u8) { a, b, c }, .b);
785800
try testSerDesAlloc(enum(u8) { a, b, c }, .c);
786801

802+
try testSerDesAlloc(enum(usize) { a, b, c }, .a);
803+
try testSerDesAlloc(enum(usize) { a, b, c }, .b);
804+
try testSerDesAlloc(enum(usize) { a, b, c }, .c);
805+
806+
try testSerDesAlloc(enum(isize) { a, b, c }, .a);
807+
try testSerDesAlloc(enum(isize) { a, b, c }, .b);
808+
try testSerDesAlloc(enum(isize) { a, b, c }, .c);
809+
787810
const TestEnum = enum(u8) { a, b, c, _ };
788811
try testSerDesAlloc(TestEnum, .a);
789812
try testSerDesAlloc(TestEnum, .b);

0 commit comments

Comments
 (0)