zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 77273103a8f9895ceab28287dffcf4d4c6fcb91b (tree)
parent 4b910e525d97276c64e98832663f0acfe8ff5cfb
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed, 15 Jan 2025 16:39:34 +0000

print_value: fix crash on undefined slice ptr

Resolves: #22418

Diffstat:
Msrc/print_value.zig | 25++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/print_value.zig b/src/print_value.zig @@ -130,16 +130,23 @@ pub fn print( inline else => |x| try writer.print("{d}", .{@as(f64, @floatCast(x))}), }, .slice => |slice| { - const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) { - .field, .arr_elem, .eu_payload, .opt_payload => unreachable, - .uav, .comptime_alloc, .comptime_field => true, - .nav, .int => false, - }; - if (print_contents) { - // TODO: eventually we want to load the slice as an array with `sema`, but that's - // currently not possible without e.g. triggering compile errors. + if (ip.isUndef(slice.ptr)) { + if (slice.len == .zero_usize) { + return writer.writeAll("&.{}"); + } + try print(.fromInterned(slice.ptr), writer, level - 1, pt, opt_sema); + } else { + const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) { + .field, .arr_elem, .eu_payload, .opt_payload => unreachable, + .uav, .comptime_alloc, .comptime_field => true, + .nav, .int => false, + }; + if (print_contents) { + // TODO: eventually we want to load the slice as an array with `sema`, but that's + // currently not possible without e.g. triggering compile errors. + } + try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema); } - try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema); try writer.writeAll("[0.."); if (level == 0) { try writer.writeAll("(...)");