authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-16 12:03:43+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-16 12:04:00+00:00
log5a957a32811602b7e2035e2046e565b3981d633d
tree72f3cd4c2e5520424cd27970c2f2df449515a166
parente6cf3ce24c42d4a2dffd4f0204a22a31eef3c562
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 5 insertions(+), 1 deletions(-)

src/Sema.zig+5-1
......@@ -5671,10 +5671,14 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I
56715671 const src = inst_data.src();
56725672 const msg_inst = try sema.resolveInst(inst_data.operand);
56735673
5674 // `panicWithMsg` would perform this coercion for us, but we can get a better
5675 // source location if we do it here.
5676 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node });
5677
56745678 if (block.is_comptime) {
56755679 return sema.fail(block, src, "encountered @panic at comptime", .{});
56765680 }
5677 try sema.panicWithMsg(block, src, msg_inst, .@"@panic");
5681 try sema.panicWithMsg(block, src, coerced_msg, .@"@panic");
56785682 return always_noreturn;
56795683}
56805684