1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! This module contains type definitions for errors and warnings which can
//! occur during compilation of a Papyri source file.

mod module_error;
mod runtime_error;
mod syntax_error;
mod type_error;
mod warning;
pub use module_error::ModuleError;
pub use runtime_error::{NameError, RuntimeError};
pub use syntax_error::SyntaxError;
pub use type_error::TypeError;
pub use warning::Warning;

mod sink;
mod sink_base;
pub use sink_base::{StackTrace, ReportingLevel, DiagSourceRange};
pub use sink::{Diagnostics, PapyriError, AlreadyReported};

/// A result type for which `Err` means a diagnostic must be reported by the
/// caller.
pub type PapyriResult<T=()> = Result<T, PapyriError>;

/// A result type for which `Err` means a diagnostic has already been reported
/// by the callee.
pub type Reported<T=()> = Result<T, AlreadyReported>;

/// Reports an internal compiler error, indicating a bug or mistake in the
/// Papyri compiler. Use `ice_at` instead if the error corresponds with some
/// code in a Papyri source file.
pub fn ice(msg: &str) -> ! {
    panic!("Internal compiler error: {msg}");
}

/// Reports an internal compiler error, indicating a bug or mistake in the
/// Papyri compiler. Use `ice` instead if the error does not correspond with
/// any particular code in a Papyri source file.
pub fn ice_at(msg: &str, src_file: &crate::utils::sourcefile::SourceFile, range: crate::utils::sourcefile::SourceRange) -> ! {
    let (line, col) = src_file.index_to_line_col(range.start);
    panic!("Internal compiler error: {msg}\n    File \"{}\", line {line}, col {col}", src_file.path_str);
}