aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/enum.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-03-05 07:37:31 +0000
committermlugg <mlugg@mlugg.co.uk>2024-03-06 21:26:38 +0000
commit20403ee41d67b02faedbee97a94fc8b9fd3781e0 (patch)
treecb51145f74df43e41b70a8a8c76e9e05251bcb3b /test/behavior/enum.zig
parenta7cac5fc8ed2d49badc6a07ee2e4e77f4ac6e6ae (diff)
downloadzig-20403ee41d67b02faedbee97a94fc8b9fd3781e0.tar.gz
zig-20403ee41d67b02faedbee97a94fc8b9fd3781e0.zip
behavior: add tests for #18816
Diffstat (limited to 'test/behavior/enum.zig')
-rw-r--r--test/behavior/enum.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig
index 91978c6dde..fab32b10d9 100644
--- a/test/behavior/enum.zig
+++ b/test/behavior/enum.zig
@@ -1242,3 +1242,24 @@ test "Non-exhaustive enum backed by comptime_int" {
e = @as(E, @enumFromInt(378089457309184723749));
try expect(@intFromEnum(e) == 378089457309184723749);
}
+
+test "matching captures causes enum equivalence" {
+ const S = struct {
+ fn Nonexhaustive(comptime I: type) type {
+ const UTag = @Type(.{ .Int = .{
+ .signedness = .unsigned,
+ .bits = @typeInfo(I).Int.bits,
+ } });
+ return enum(UTag) { _ };
+ }
+ };
+
+ comptime assert(S.Nonexhaustive(u8) == S.Nonexhaustive(i8));
+ comptime assert(S.Nonexhaustive(u16) == S.Nonexhaustive(i16));
+ comptime assert(S.Nonexhaustive(u8) != S.Nonexhaustive(u16));
+
+ const a: S.Nonexhaustive(u8) = @enumFromInt(123);
+ const b: S.Nonexhaustive(i8) = @enumFromInt(123);
+ comptime assert(@TypeOf(a) == @TypeOf(b));
+ try expect(@intFromEnum(a) == @intFromEnum(b));
+}