microcad_lang/resolve/
resolve_error.rs1use miette::Diagnostic;
7use thiserror::Error;
8
9use crate::{diag::*, parse::*, syntax::*};
10use crate::src_ref::{SrcRef, SrcReferrer};
11
12#[derive(Debug, Error, Diagnostic)]
14pub enum ResolveError {
15 #[error("Parse Error: {0}")]
17 ParseError(#[from] ParseErrorWithSource),
18
19 #[error("Could not find a file with hash {0}")]
21 UnknownHash(u64),
22
23 #[error("Hash is zero")]
25 NulHash,
26
27 #[error("External symbol `{0}` not found")]
29 ExternalSymbolNotFound(QualifiedName),
30
31 #[error("External path `{0}` not found")]
33 ExternalPathNotFound(std::path::PathBuf),
34
35 #[error("Could not find a file with path {0}")]
37 FileNotFound(std::path::PathBuf),
38
39 #[error("Symbol {0} not found while resolving.")]
41 SymbolNotFound(QualifiedName),
42
43 #[error("Symbol {0} must be loaded from {1}")]
45 SymbolMustBeLoaded(QualifiedName, std::path::PathBuf),
46
47 #[error("Symbol {0} is not a value")]
49 NotAValue(QualifiedName),
50
51 #[error("Declaration of {0} not allowed within {1}")]
53 DeclNotAllowed(Identifier, QualifiedName),
54
55 #[error("Ambiguous external module files found {0:?}")]
57 AmbiguousExternals(Vec<std::path::PathBuf>),
58
59 #[error("Symbol {0} already defined")]
61 SymbolAlreadyDefined(QualifiedName),
62
63 #[error("Ambiguous symbol found: {0}")]
65 AmbiguousSymbol(QualifiedName, QualifiedNames),
66
67 #[error("{0}")]
69 ScanDirError(#[from] scan_dir::Error),
70
71 #[error("Invalid path: {0:?}")]
73 InvalidPath(std::path::PathBuf),
74
75 #[error("Diagnostic error: {0}")]
77 DiagError(#[from] DiagError),
78
79 #[error("{0} is not available within {1}")]
81 StatementNotSupported(String, String),
82
83 #[error("Resolve failed")]
85 ResolveCheckFailed,
86
87 #[error("Symbol {0} is private")]
89 SymbolIsPrivate(QualifiedName),
90
91 #[error("{0}")]
93 IoError(#[from] std::io::Error),
94
95 #[error(
97 "Source of module '{0}' could not be found in {1:?} (expecting a file '{0}.µcad' or '{0}/mod.µcad')"
98 )]
99 SourceFileNotFound(
100 #[label("module not found")]
101 Identifier,
102 std::path::PathBuf
103 ),
104
105 #[error("Wrong lookup target")]
107 WrongTarget,
108
109 #[error("Statement not allowed within workbenches")]
111 IllegalWorkbenchStatement,
112
113 #[error("Code between initializers is not allowed")]
115 CodeBetweenInitializers,
116
117 #[error("Statement not allowed prior initializers")]
119 StatementNotAllowedPriorInitializers,
120}
121
122impl SrcReferrer for ResolveError {
123 fn src_ref(&self) -> SrcRef {
124 match self {
125 ResolveError::SourceFileNotFound(identifier, _) => identifier.src_ref(),
126 _ => SrcRef(None),
127 }
128 }
129}
130
131pub type ResolveResult<T> = std::result::Result<T, ResolveError>;