aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 9f4d3f0298..f85e783342 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -2127,3 +2127,26 @@ test "struct containing optional pointer to array of @This()" {
_ = &s;
try expect(s.x.?[0].x == null);
}
+
+test "matching captures causes struct equivalence" {
+ const S = struct {
+ fn UnsignedWrapper(comptime I: type) type {
+ const bits = @typeInfo(I).Int.bits;
+ return struct {
+ x: @Type(.{ .Int = .{
+ .signedness = .unsigned,
+ .bits = bits,
+ } }),
+ };
+ }
+ };
+
+ comptime assert(S.UnsignedWrapper(u8) == S.UnsignedWrapper(i8));
+ comptime assert(S.UnsignedWrapper(u16) == S.UnsignedWrapper(i16));
+ comptime assert(S.UnsignedWrapper(u8) != S.UnsignedWrapper(u16));
+
+ const a: S.UnsignedWrapper(u8) = .{ .x = 10 };
+ const b: S.UnsignedWrapper(i8) = .{ .x = 10 };
+ comptime assert(@TypeOf(a) == @TypeOf(b));
+ try expect(a.x == b.x);
+}