From 5a957a32811602b7e2035e2046e565b3981d633d Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 16 Feb 2024 12:03:43 +0000 Subject: [PATCH] Sema: improved source location for @panic operand coercion error Similar to the previous commit, errors coercing the panic message to `[]const u8` now point at the operand to `@panic` rather than the actual builtin call. --- src/Sema.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index ce231af6fd..1ee036c15c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5671,10 +5671,14 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I const src = inst_data.src(); const msg_inst = try sema.resolveInst(inst_data.operand); + // `panicWithMsg` would perform this coercion for us, but we can get a better + // source location if we do it here. + const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node }); + if (block.is_comptime) { return sema.fail(block, src, "encountered @panic at comptime", .{}); } - try sema.panicWithMsg(block, src, msg_inst, .@"@panic"); + try sema.panicWithMsg(block, src, coerced_msg, .@"@panic"); return always_noreturn; }