union Note [src]

Fields

zoir: Zoir.CompileError.Note
type_check: TypeCheckFailure.Note

Members

Source

pub const Note = union(enum) { zoir: Zoir.CompileError.Note, type_check: TypeCheckFailure.Note, pub const Iterator = struct { index: usize = 0, err: Error, diag: *const Diagnostics, pub fn next(self: *@This()) ?Note { switch (self.err) { .zoir => |err| { if (self.index >= err.note_count) return null; const note = err.getNotes(self.diag.zoir)[self.index]; self.index += 1; return .{ .zoir = note }; }, .type_check => |err| { if (self.index >= err.getNoteCount()) return null; const note = err.getNote(self.index); self.index += 1; return .{ .type_check = note }; }, } } }; fn formatMessage(self: []const u8, w: *std.Io.Writer) std.Io.Writer.Error!void { // Just writes the string for now, but we're keeping this behind a formatter so we have // the option to extend it in the future to print more advanced messages (like `Error` // does) without breaking the API. try w.writeAll(self); } pub fn fmtMessage(self: Note, diag: *const Diagnostics) std.fmt.Alt([]const u8, Note.formatMessage) { return .{ .data = switch (self) { .zoir => |note| note.msg.get(diag.zoir), .type_check => |note| note.msg, } }; } pub fn getLocation(self: Note, diag: *const Diagnostics) Ast.Location { switch (self) { .zoir => |note| return zoirErrorLocation(diag.ast, note.token, note.node_or_offset), .type_check => |note| return diag.ast.tokenLocation(note.offset, note.token), } } }