diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-31 12:57:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-31 12:57:53 -0700 |
| commit | 1ab15b6c9c529c9acc85f4b0bf3fcaea97a5a48e (patch) | |
| tree | f4c713785c0fa760ab8da49fcea5a90a841111dc /src/value.zig | |
| parent | b35490c21732d74232680d2de2deb89f97356c0d (diff) | |
| parent | 02dc0732604236a57b43b9612d9b0571f06f905a (diff) | |
| download | zig-1ab15b6c9c529c9acc85f4b0bf3fcaea97a5a48e.tar.gz zig-1ab15b6c9c529c9acc85f4b0bf3fcaea97a5a48e.zip | |
Merge pull request #12289 from Vexu/stage2
Stage2: reify functions + fixes
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/value.zig b/src/value.zig index fd71aeabdc..3994040ba6 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2292,25 +2292,13 @@ pub const Value = extern union { } }, .Struct => { - if (ty.isTupleOrAnonStruct()) { - const fields = ty.tupleFields(); - for (fields.values) |field_val, i| { - field_val.hash(fields.types[i], hasher, mod); - } - return; - } - const fields = ty.structFields().values(); - if (fields.len == 0) return; switch (val.tag()) { - .empty_struct_value => { - for (fields) |field| { - field.default_val.hash(field.ty, hasher, mod); - } - }, + .empty_struct_value => {}, .aggregate => { const field_values = val.castTag(.aggregate).?.data; for (field_values) |field_val, i| { - field_val.hash(fields[i].ty, hasher, mod); + const field_ty = ty.structFieldType(i); + field_val.hash(field_ty, hasher, mod); } }, else => unreachable, @@ -2798,6 +2786,19 @@ pub const Value = extern union { return self.isUndef(); } + /// Returns true if any value contained in `self` is undefined. + /// TODO: check for cases such as array that is not marked undef but all the element + /// values are marked undef, or struct that is not marked undef but all fields are marked + /// undef, etc. + pub fn anyUndef(self: Value) bool { + if (self.castTag(.aggregate)) |aggregate| { + for (aggregate.data) |val| { + if (val.anyUndef()) return true; + } + } + return self.isUndef(); + } + /// Asserts the value is not undefined and not unreachable. /// Integer value 0 is considered null because of C pointers. pub fn isNull(self: Value) bool { |
