diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-03-05 07:37:31 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-03-06 21:26:38 +0000 |
| commit | 20403ee41d67b02faedbee97a94fc8b9fd3781e0 (patch) | |
| tree | cb51145f74df43e41b70a8a8c76e9e05251bcb3b /test/behavior/type.zig | |
| parent | a7cac5fc8ed2d49badc6a07ee2e4e77f4ac6e6ae (diff) | |
| download | zig-20403ee41d67b02faedbee97a94fc8b9fd3781e0.tar.gz zig-20403ee41d67b02faedbee97a94fc8b9fd3781e0.zip | |
behavior: add tests for #18816
Diffstat (limited to 'test/behavior/type.zig')
| -rw-r--r-- | test/behavior/type.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 1ce31fecfd..d1310a2167 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -2,6 +2,7 @@ const std = @import("std"); const builtin = @import("builtin"); const Type = std.builtin.Type; const testing = std.testing; +const assert = std.debug.assert; fn testTypes(comptime types: []const type) !void { inline for (types) |testType| { @@ -734,3 +735,28 @@ test "struct field names sliced at comptime from larger string" { try testing.expectEqualStrings("f3", gen_fields[2].name); } } + +test "matching captures causes opaque equivalence" { + const S = struct { + fn UnsignedId(comptime I: type) type { + const U = @Type(.{ .Int = .{ + .signedness = .unsigned, + .bits = @typeInfo(I).Int.bits, + } }); + return opaque { + fn id(x: U) U { + return x; + } + }; + } + }; + + comptime assert(S.UnsignedId(u8) == S.UnsignedId(i8)); + comptime assert(S.UnsignedId(u16) == S.UnsignedId(i16)); + comptime assert(S.UnsignedId(u8) != S.UnsignedId(u16)); + + const a = S.UnsignedId(u8).id(123); + const b = S.UnsignedId(i8).id(123); + comptime assert(@TypeOf(a) == @TypeOf(b)); + try testing.expect(a == b); +} |
