diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-31 01:25:02 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:47:57 -0700 |
| commit | 71c4077c359096d0706a251a10eeae6c41f299ca (patch) | |
| tree | 52260738aac6b4ff5f2954e6253ac7fa38b0d744 /src | |
| parent | 26fac15f485e89dc7106256e1aa79184c1761efd (diff) | |
| download | zig-71c4077c359096d0706a251a10eeae6c41f299ca.tar.gz zig-71c4077c359096d0706a251a10eeae6c41f299ca.zip | |
Value: fix null test for c pointers
Diffstat (limited to 'src')
| -rw-r--r-- | src/value.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/value.zig b/src/value.zig index 62a83c7901..db37d8e9e7 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2131,19 +2131,20 @@ pub const Value = struct { } /// Asserts the value is not undefined and not unreachable. - /// Integer value 0 is considered null because of C pointers. + /// C pointers with an integer value of 0 are also considered null. pub fn isNull(val: Value, mod: *Module) bool { return switch (val.toIntern()) { .undef => unreachable, .unreachable_value => unreachable, - .null_value => true, - else => return switch (mod.intern_pool.indexToKey(val.toIntern())) { .undef => unreachable, - .int => { - var buf: BigIntSpace = undefined; - return val.toBigInt(&buf, mod).eqZero(); + .ptr => |ptr| switch (ptr.addr) { + .int => { + var buf: BigIntSpace = undefined; + return val.toBigInt(&buf, mod).eqZero(); + }, + else => false, }, .opt => |opt| opt.val == .none, else => false, |
