Skip to main content

yulang_monomorphize/
diagnostic.rs

1use std::fmt;
2
3use yulang_typed_ir as typed_ir;
4
5pub type MonomorphizeResult<T> = Result<T, MonomorphizeDiagnostic>;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum MonomorphizeDiagnostic {
9    MissingBinding {
10        binding: typed_ir::Path,
11    },
12    UnsupportedRootShape,
13    PrincipalTypeIsNotCallable {
14        binding: typed_ir::Path,
15        actual: typed_ir::Type,
16    },
17    IncompleteGraph {
18        binding: typed_ir::Path,
19    },
20    ConflictingBounds {
21        var: typed_ir::TypeVar,
22        previous: typed_ir::Type,
23        next: typed_ir::Type,
24    },
25}
26
27#[derive(Debug)]
28pub enum MonomorphizeError {
29    Finalize(MonomorphizeDiagnostic),
30    Runtime(yulang_runtime_types::RuntimeError),
31}
32
33impl From<MonomorphizeDiagnostic> for MonomorphizeError {
34    fn from(error: MonomorphizeDiagnostic) -> Self {
35        Self::Finalize(error)
36    }
37}
38
39impl From<yulang_runtime_types::RuntimeError> for MonomorphizeError {
40    fn from(error: yulang_runtime_types::RuntimeError) -> Self {
41        Self::Runtime(error)
42    }
43}
44
45impl fmt::Display for MonomorphizeError {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        match self {
48            Self::Finalize(error) => write!(f, "runtime-finalize failed: {error:?}"),
49            Self::Runtime(error) => write!(f, "{error}"),
50        }
51    }
52}
53
54impl std::error::Error for MonomorphizeError {}