aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-04-05 02:48:00 -0400
committerAndrew Kelley <andrew@ziglang.org>2024-04-06 12:53:09 -0700
commit4e8553660405a063d8abd335a600714af121aed9 (patch)
treec4522378f427ddb62c6eb4c638d55c10312d4beb /test/behavior
parent9ab6d9106787e76ecba817b40c804be38aa6cfe7 (diff)
downloadzig-4e8553660405a063d8abd335a600714af121aed9.tar.gz
zig-4e8553660405a063d8abd335a600714af121aed9.zip
Builder: fix encoding big integers in bitcode
Closes #19543
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/enum.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig
index fab32b10d9..77b22f82aa 100644
--- a/test/behavior/enum.zig
+++ b/test/behavior/enum.zig
@@ -1263,3 +1263,44 @@ test "matching captures causes enum equivalence" {
comptime assert(@TypeOf(a) == @TypeOf(b));
try expect(@intFromEnum(a) == @intFromEnum(b));
}
+
+test "large enum field values" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
+
+ {
+ const E = enum(u64) { min = std.math.minInt(u64), max = std.math.maxInt(u64) };
+ var e: E = .min;
+ try expect(e == .min);
+ try expect(@intFromEnum(e) == std.math.minInt(u64));
+ e = .max;
+ try expect(e == .max);
+ try expect(@intFromEnum(e) == std.math.maxInt(u64));
+ }
+ {
+ const E = enum(i64) { min = std.math.minInt(i64), max = std.math.maxInt(i64) };
+ var e: E = .min;
+ try expect(e == .min);
+ try expect(@intFromEnum(e) == std.math.minInt(i64));
+ e = .max;
+ try expect(e == .max);
+ try expect(@intFromEnum(e) == std.math.maxInt(i64));
+ }
+ {
+ const E = enum(u128) { min = std.math.minInt(u128), max = std.math.maxInt(u128) };
+ var e: E = .min;
+ try expect(e == .min);
+ try expect(@intFromEnum(e) == std.math.minInt(u128));
+ e = .max;
+ try expect(e == .max);
+ try expect(@intFromEnum(e) == std.math.maxInt(u128));
+ }
+ {
+ const E = enum(i128) { min = std.math.minInt(i128), max = std.math.maxInt(i128) };
+ var e: E = .min;
+ try expect(e == .min);
+ try expect(@intFromEnum(e) == std.math.minInt(i128));
+ e = .max;
+ try expect(e == .max);
+ try expect(@intFromEnum(e) == std.math.maxInt(i128));
+ }
+}