1#![allow(unused, unused_assignments)]
7
8use crate::{eval::*, model::OutputType, parse::*, resolve::*, syntax::*, ty::*, value::*};
9use miette::Diagnostic;
10use thiserror::Error;
11
12#[derive(Debug, Error, Diagnostic)]
14#[allow(missing_docs)]
15pub enum EvalError {
16 #[error("Not implemented: {0}")]
18 Todo(String),
19
20 #[error("List index out of bounds: {index} >= {len}")]
22 ListIndexOutOfBounds {
23 index: usize,
25 len: usize,
27 },
28
29 #[error("Type mismatch for `{id}`: expected {expected}, got {found}")]
31 TypeMismatch {
32 id: Identifier,
34 expected: Type,
36 found: Type,
38 },
39
40 #[error("Array elements have different types: {0}")]
42 ArrayElementsDifferentTypes(TypeList),
43
44 #[error("Symbol {0} not found.")]
46 SymbolNotFound(QualifiedName),
47
48 #[error("No symbols found to use in {0}")]
50 NoSymbolsToUse(QualifiedName),
51
52 #[error("Unexpectedly found symbol {0}")]
54 SymbolFound(QualifiedName),
55
56 #[error("Symbol `{0}` cannot be called.")]
58 SymbolCannotBeCalled(QualifiedName),
59
60 #[error("Ambiguous symbol {0} might be one of the following: {1}")]
62 AmbiguousSymbol(QualifiedName, QualifiedNames),
63
64 #[error("Local symbol not found: {0}")]
66 LocalNotFound(Identifier),
67
68 #[error("Property not found: {0}")]
70 PropertyNotFound(Identifier),
71
72 #[error("Not a property id: {0}")]
74 NoPropertyId(QualifiedName),
75
76 #[error("Argument count mismatch: expected {expected}, got {found} in {args}")]
78 ArgumentCountMismatch {
79 args: String,
81 expected: usize,
83 found: usize,
85 },
86
87 #[error("Invalid argument type: {0}")]
89 InvalidArgumentType(Type),
90
91 #[error("Unexpected argument: {0}: {1}")]
93 UnexpectedArgument(Identifier, Type),
94
95 #[error("Assertion failed: {0}")]
97 AssertionFailed(String),
98
99 #[error("Expected type `{expected}`, found type `{found}")]
101 ExpectedType {
102 expected: Type,
104 found: Type,
106 },
107
108 #[error("Diagnostic error: {0}")]
110 DiagError(#[from] DiagError),
111
112 #[error("Local stack needed to store {0}")]
114 LocalStackEmpty(Identifier),
115
116 #[error("Unexpected stack frame of type '{1}' cannot store {0}")]
118 WrongStackFrame(Identifier, &'static str),
119
120 #[error("Value Error: {0}")]
122 ValueError(#[from] ValueError),
123
124 #[error("Unknown method `{0}`")]
126 UnknownMethod(QualifiedName),
127
128 #[error("Parsing error {0}")]
130 ParseError(#[from] ParseError),
131
132 #[error("{0} statement not available here")]
134 StatementNotSupported(&'static str),
135
136 #[error("Properties have not been initialized: {0}")]
138 UninitializedProperties(IdentifierList),
139
140 #[error("Unexpected {0} {1} within expression")]
142 UnexpectedNested(&'static str, Identifier),
143
144 #[error("No variables allowed in {0}")]
146 NoVariablesAllowedIn(&'static str),
147
148 #[error("Attribute error: {0}")]
150 AttributeError(#[from] AttributeError),
151
152 #[error("Missing arguments: {0}")]
154 MissingArguments(IdentifierList),
155
156 #[error("Too many arguments: {0}")]
158 TooManyArguments(IdentifierList),
159
160 #[error("Arguments match by identifier but have incompatible types: {0}")]
162 IdMatchButNotType(String),
163
164 #[error("Builtin error: {0}")]
166 BuiltinError(String),
167
168 #[error("Parameter not found by type '{0}'")]
170 ParameterByTypeNotFound(Type),
171
172 #[error("Multiplicity not allowed '{0}'")]
174 MultiplicityNotAllowed(IdentifierList),
175
176 #[error("Cannot mix 2d and 3d geometries")]
178 CannotMixGeometry,
179
180 #[error("If condition is not a boolean: {0}")]
182 IfConditionIsNotBool(String),
183
184 #[error("Workbench {name} cannot find initialization for those arguments")]
186 #[diagnostic(help("Possible initializations: \n\t{}", possible_params.join("\n\t")))]
187 NoInitializationFound {
188 #[label("Got: {name}( {actual_params} )")]
189 src_ref: SrcRef,
190 name: Identifier,
191 actual_params: String,
192 possible_params: Vec<String>,
193 },
194 #[error("Workbench {name} has ambiguous initialization for those arguments")]
196 #[diagnostic(help("Ambiguous initializations: \n\t{}", ambiguous_params.join("\n\t")))]
197 AmbiguousInitialization {
198 #[label("Got: {name}( {actual_params} )")]
199 src_ref: SrcRef,
200 name: Identifier,
201 actual_params: String,
202 ambiguous_params: Vec<String>,
203 },
204
205 #[error("Building plan incomplete. Missing properties: {0}")]
207 BuildingPlanIncomplete(IdentifierList),
208
209 #[error("This expression statement did not produce any model")]
211 EmptyModelExpression,
212
213 #[error("{0} {1} has empty body")]
215 WarnEmptyWorkbench(String, Identifier),
216
217 #[error("The {0} workbench produced a 2D output, but expected {2} output.")]
219 WorkbenchInvalidOutput(WorkbenchKind, OutputType, OutputType),
220
221 #[error("The {0} workbench will produce no {1} output.")]
223 WorkbenchNoOutput(WorkbenchKind, OutputType),
224
225 #[error("Unexpected source file {0} in expression")]
227 InvalidSelfReference(Identifier),
228
229 #[error("Resolve error: {0}")]
231 #[diagnostic(transparent)]
232 ResolveError(ResolveError),
233
234 #[error("{0} is not operation.")]
236 NotAnOperation(QualifiedName),
237
238 #[error("Calling operation on empty geometry")]
240 OperationOnEmptyGeometry,
241
242 #[error("Cannot call operation without workpiece.")]
244 CannotCallOperationWithoutWorkpiece,
245
246 #[error("Missing return statement in {0}")]
248 MissingReturn(QualifiedName),
249
250 #[error("Missing model in workbench")]
252 NoModelInWorkbench,
253
254 #[error("Found a symbol and a property with names {0} and {1}")]
256 AmbiguousProperty(QualifiedName, Identifier),
257
258 #[error("Value {name} already in defined: {value}")]
260 #[diagnostic(help("Values in microcad are immutable"))]
261 ValueAlreadyDefined {
262 #[label(primary, "{name} is already defined")]
264 location: SrcRef,
265 name: Identifier,
267 value: String,
269 #[label("Previously defined here")]
271 previous_location: SrcRef,
272 },
273
274 #[error("Assignment failed because {0} is not an l-value")]
276 NotAnLValue(Identifier),
277
278 #[error("Symbol {what} is private from within {within}")]
280 SymbolIsPrivate {
281 what: QualifiedName,
283 within: QualifiedName,
285 },
286
287 #[error("Symbol {what} (aliased from {alias}) is private from within {within}")]
289 SymbolBehindAliasIsPrivate {
290 what: QualifiedName,
292 alias: QualifiedName,
294 within: QualifiedName,
296 },
297
298 #[error("Unused global symbol {0}.")]
300 UnusedGlobalSymbol(String),
301
302 #[error("Unused local {0}.")]
304 UnusedLocal(Identifier),
305
306 #[error("Evaluation aborted because of prior resolve errors!")]
308 ResolveFailed,
309
310 #[error("Bad range, first number ({0}) must be smaller than last ({1})")]
312 BadRange(i64, i64),
313}
314
315pub type EvalResult<T> = std::result::Result<T, EvalError>;
317
318impl From<ResolveError> for EvalError {
319 fn from(err: ResolveError) -> Self {
320 match err {
321 ResolveError::SymbolNotFound(name) => EvalError::SymbolNotFound(name),
322 other => EvalError::ResolveError(other),
323 }
324 }
325}