print_value: fix crash on undefined slice ptr

Resolves: #22418
This commit is contained in:
mlugg 2025-01-15 16:39:34 +00:00 committed by Matthew Lugg
parent 4b910e525d
commit 77273103a8

View File

@ -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("(...)");