diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-24 12:06:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-24 12:07:14 -0700 |
| commit | ce65ca434584783c30c80b611e02428a26f65512 (patch) | |
| tree | 326dc8e23e020b55c3a2901e033bac6b37c7fd7a /src/value.zig | |
| parent | f7b090d7076a20a614bf20cac05e5e18c06ad18a (diff) | |
| download | zig-ce65ca434584783c30c80b611e02428a26f65512.tar.gz zig-ce65ca434584783c30c80b611e02428a26f65512.zip | |
stage2: refactor coercePeerTypes and fix C ptr cmp with null
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/value.zig b/src/value.zig index cbfeea9786..19c2a73666 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1790,12 +1790,31 @@ pub const Value = extern union { return self.tag() == .undef; } - /// Valid for all types. Asserts the value is not undefined and not unreachable. + /// 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 { return switch (self.tag()) { .null_value => true, .opt_payload => false, + // If it's not one of those two tags then it must be a C pointer value, + // in which case the value 0 is null and other values are non-null. + + .zero, + .bool_false, + .the_only_possible_value, + => true, + + .one, + .bool_true, + => false, + + .int_u64, + .int_i64, + .int_big_positive, + .int_big_negative, + => compareWithZero(self, .eq), + .undef => unreachable, .unreachable_value => unreachable, .inferred_alloc => unreachable, |
