Skip to content

unify the two ways that compile errors get printed to stderr #8872

Description

@andrewrk

pubfnrenderToStdErr(msg: Message, ttyconf: std.debug.TTY.Config) void {

vs

fnprintErrMsgToFile(

Probably the latter should be changed to convert to the Compilation error message struct. You can see an example of this code here:

zig/src/Module.zig

Lines 2467 to 2476 in 63aabbb

tryfile.tree.renderError(parse_err, msg.writer());
consterr_msg=trygpa.create(ErrorMsg);
err_msg.*= .{
.src_loc= .{
.file_scope=file,
.parent_decl_node=0,
.lazy= .{ .byte_abs=token_starts[parse_err.token] },
},
.msg=msg.toOwnedSlice(),
};

and then

zig/src/Compilation.zig

Lines 394 to 441 in 63aabbb

fnadd(
module: *Module,
arena: *std.heap.ArenaAllocator,
errors: *std.ArrayList(Message),
module_err_msg: Module.ErrorMsg,
) !void {
constnotes=tryarena.allocator.alloc(Message, module_err_msg.notes.len);
for (notes) |*note, i| {
constmodule_note=module_err_msg.notes[i];
constsource=trymodule_note.src_loc.file_scope.getSource(module.gpa);
constbyte_offset=trymodule_note.src_loc.byteOffset(module.gpa);
constloc=std.zig.findLineColumn(source, byte_offset);
constsub_file_path=module_note.src_loc.file_scope.sub_file_path;
note.*= .{
.src= .{
.src_path=tryarena.allocator.dupe(u8, sub_file_path),
.msg=tryarena.allocator.dupe(u8, module_note.msg),
.byte_offset=byte_offset,
.line=@intCast(u32, loc.line),
.column=@intCast(u32, loc.column),
.source_line=tryarena.allocator.dupe(u8, loc.source_line),
},
};
}
if (module_err_msg.src_loc.lazy==.entire_file) {
tryerrors.append(.{
.plain= .{
.msg=tryarena.allocator.dupe(u8, module_err_msg.msg),
},
});
return;
}
constsource=trymodule_err_msg.src_loc.file_scope.getSource(module.gpa);
constbyte_offset=trymodule_err_msg.src_loc.byteOffset(module.gpa);
constloc=std.zig.findLineColumn(source, byte_offset);
constsub_file_path=module_err_msg.src_loc.file_scope.sub_file_path;
tryerrors.append(.{
.src= .{
.src_path=tryarena.allocator.dupe(u8, sub_file_path),
.msg=tryarena.allocator.dupe(u8, module_err_msg.msg),
.byte_offset=byte_offset,
.line=@intCast(u32, loc.line),
.column=@intCast(u32, loc.column),
.notes=notes,
.source_line=tryarena.allocator.dupe(u8, loc.source_line),
},
});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions