aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-28 20:05:21 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-02-28 20:05:21 -0700
commitd5131e91eba9324eda3a2ae47eb2aa4530c87e83 (patch)
tree62abf5656b3392f738d48f848d3fc64bbc60c19a /src/value.zig
parent157f66ec077ad02f08891bec1a426c0ffef98e09 (diff)
downloadzig-d5131e91eba9324eda3a2ae47eb2aa4530c87e83.tar.gz
zig-d5131e91eba9324eda3a2ae47eb2aa4530c87e83.zip
Sema: complete the Type.hash function
Similar to how Type.eql was reworked in the previous commit, this commit reworks Type.hash to check all the different kinds of tags that a Type can be represented with. It also completes the implementation for all types except error sets, which need to have Type.eql enhanced as well.
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/value.zig b/src/value.zig
index 51f678aaaa..a740a35b79 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -2040,9 +2040,19 @@ pub const Value = extern union {
}
const fields = ty.structFields().values();
if (fields.len == 0) return;
- const field_values = val.castTag(.@"struct").?.data;
- for (field_values) |field_val, i| {
- field_val.hash(fields[i].ty, hasher);
+ switch (val.tag()) {
+ .empty_struct_value => {
+ for (fields) |field| {
+ field.default_val.hash(field.ty, hasher);
+ }
+ },
+ .@"struct" => {
+ const field_values = val.castTag(.@"struct").?.data;
+ for (field_values) |field_val, i| {
+ field_val.hash(fields[i].ty, hasher);
+ }
+ },
+ else => unreachable,
}
},
.Optional => {