aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta
diff options
context:
space:
mode:
authorJulius Putra Tanu Setiaji <indocomsoft@gmail.com>2020-12-26 19:16:53 +0800
committerJulius Putra Tanu Setiaji <indocomsoft@gmail.com>2020-12-26 19:43:15 +0800
commitf9506e9155d93c14958f9cd559b855a00bf96e11 (patch)
tree1cef881dc4286d95b67076131488010e9cab2382 /lib/std/meta
parentd9133b9ae056aa70bf6ed83c4d080022127d3397 (diff)
downloadzig-f9506e9155d93c14958f9cd559b855a00bf96e11.tar.gz
zig-f9506e9155d93c14958f9cd559b855a00bf96e11.zip
Handle unions in autoHash
Diffstat (limited to 'lib/std/meta')
-rw-r--r--lib/std/meta/trait.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig
index 1c2f2df513..180e0b8664 100644
--- a/lib/std/meta/trait.zig
+++ b/lib/std/meta/trait.zig
@@ -530,10 +530,53 @@ test "std.meta.trait.hasUniqueRepresentation" {
testing.expect(hasUniqueRepresentation(TestStruct3));
+ const TestStruct4 = struct {
+ a: []const u8
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestStruct4));
+
+ const TestStruct5 = struct {
+ a: TestStruct4
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestStruct5));
+
+ const TestUnion1 = packed union {
+ a: u32,
+ b: u16,
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestUnion1));
+
+ const TestUnion2 = extern union {
+ a: u32,
+ b: u16,
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestUnion2));
+
+ const TestUnion3 = union {
+ a: u32,
+ b: u16,
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestUnion3));
+
+ const TestUnion4 = union(enum) {
+ a: u32,
+ b: u16,
+ };
+
+ testing.expect(!hasUniqueRepresentation(TestUnion4));
+
inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
testing.expect(hasUniqueRepresentation(T));
}
inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
testing.expect(!hasUniqueRepresentation(T));
}
+
+ testing.expect(!hasUniqueRepresentation([]u8));
+ testing.expect(!hasUniqueRepresentation([]const u8));
}