1use crate::{eval::*, model::OutputType, parse::*, resolve::*, syntax::*, ty::*, value::*};
7use thiserror::Error;
8
9#[derive(Debug, Error)]
11pub enum EvalError {
12 #[error("Not implemented: {0}")]
14 Todo(String),
15
16 #[error("List index out of bounds: {index} >= {len}")]
18 ListIndexOutOfBounds {
19 index: usize,
21 len: usize,
23 },
24
25 #[error("Type mismatch for `{id}`: expected {expected}, got {found}")]
27 TypeMismatch {
28 id: Identifier,
30 expected: Type,
32 found: Type,
34 },
35
36 #[error("Array elements have different types: {0}")]
38 ArrayElementsDifferentTypes(TypeList),
39
40 #[error("Symbol {0} not found.")]
42 SymbolNotFound(QualifiedName),
43
44 #[error("No symbols found to use in {0}")]
46 NoSymbolsToUse(QualifiedName),
47
48 #[error("Unexpectedly found symbol {0}")]
50 SymbolFound(QualifiedName),
51
52 #[error("Symbol `{0}` cannot be called.")]
54 SymbolCannotBeCalled(QualifiedName),
55
56 #[error("Ambiguous symbol {0} might be one of the following: {1}")]
58 AmbiguousSymbol(QualifiedName, QualifiedNames),
59
60 #[error("Local symbol not found: {0}")]
62 LocalNotFound(Identifier),
63
64 #[error("Property not found: {0}")]
66 PropertyNotFound(Identifier),
67
68 #[error("Not a property id: {0}")]
70 NoPropertyId(QualifiedName),
71
72 #[error("Argument count mismatch: expected {expected}, got {found} in {args}")]
74 ArgumentCountMismatch {
75 args: String,
77 expected: usize,
79 found: usize,
81 },
82
83 #[error("Invalid argument type: {0}")]
85 InvalidArgumentType(Type),
86
87 #[error("Unexpected argument: {0}: {1}")]
89 UnexpectedArgument(Identifier, Type),
90
91 #[error("Assertion failed: {0}")]
93 AssertionFailed(String),
94
95 #[error("Expected type `{expected}`, found type `{found}")]
97 ExpectedType {
98 expected: Type,
100 found: Type,
102 },
103
104 #[error("Diagnostic error: {0}")]
106 DiagError(#[from] DiagError),
107
108 #[error("Local stack needed to store {0}")]
110 LocalStackEmpty(Identifier),
111
112 #[error("Unexpected stack frame of type '{1}' cannot store {0}")]
114 WrongStackFrame(Identifier, &'static str),
115
116 #[error("Value Error: {0}")]
118 ValueError(#[from] ValueError),
119
120 #[error("Unknown method `{0}`")]
122 UnknownMethod(QualifiedName),
123
124 #[error("Parsing error {0}")]
126 ParseError(#[from] ParseError),
127
128 #[error("{0} statement not available here")]
130 StatementNotSupported(&'static str),
131
132 #[error("Properties have not been initialized: {0}")]
134 UninitializedProperties(IdentifierList),
135
136 #[error("Unexpected {0} {1} within expression")]
138 UnexpectedNested(&'static str, Identifier),
139
140 #[error("No variables allowed in {0}")]
142 NoVariablesAllowedIn(&'static str),
143
144 #[error("Attribute error: {0}")]
146 AttributeError(#[from] AttributeError),
147
148 #[error("Missing arguments: {0}")]
150 MissingArguments(IdentifierList),
151
152 #[error("Too many arguments: {0}")]
154 TooManyArguments(IdentifierList),
155
156 #[error("Builtin error: {0}")]
158 BuiltinError(String),
159
160 #[error("Parameter not found by type '{0}'")]
162 ParameterByTypeNotFound(Type),
163
164 #[error("Multiplicity not allowed '{0}'")]
166 MultiplicityNotAllowed(IdentifierList),
167
168 #[error("Cannot mix 2d and 3d geometries")]
170 CannotMixGeometry,
171
172 #[error("If condition is not a boolean: {0}")]
174 IfConditionIsNotBool(String),
175
176 #[error("Workbench {0} cannot find initialization for those arguments")]
178 NoInitializationFound(Identifier),
179
180 #[error("Workbench plan incomplete. Missing properties: {0}")]
182 BuildingPlanIncomplete(IdentifierList),
183
184 #[error("This expression statement did not produce any model")]
186 EmptyModelExpression,
187
188 #[error("{0} {1} has empty body")]
190 WarnEmptyWorkbench(String, Identifier),
191
192 #[error("The {0} workbench produced a 2D output, but expected {2} output.")]
194 WorkbenchInvalidOutput(WorkbenchKind, OutputType, OutputType),
195
196 #[error("The {0} workbench will produce no {1} output.")]
198 WorkbenchNoOutput(WorkbenchKind, OutputType),
199
200 #[error("Unexpected source file {0} in expression")]
202 InvalidSelfReference(Identifier),
203
204 #[error("Resolve error: {0}")]
206 ResolveError(ResolveError),
207
208 #[error("{0} is not operation.")]
210 NotAnOperation(QualifiedName),
211
212 #[error("Calling operation on empty geometry")]
214 OperationOnEmptyGeometry,
215
216 #[error("Cannot call operation without workpiece.")]
218 CannotCallOperationWithoutWorkpiece,
219
220 #[error("Missing return statement in {0}")]
222 MissingReturn(QualifiedName),
223
224 #[error("Missing model in workbench")]
226 NoModelInWorkbench,
227
228 #[error("Found a symbol and a property with names {0} and {1}")]
230 AmbiguousProperty(QualifiedName, Identifier),
231
232 #[error("Value {0} already in defined: {1} (at line {2})")]
234 ValueAlreadyDefined(Identifier, String, SrcRef),
235
236 #[error("Assignment failed because {0} is not an l-value")]
238 NotAnLValue(Identifier),
239
240 #[error("Symbol {what} is private from within {within}")]
242 SymbolIsPrivate {
243 what: QualifiedName,
245 within: QualifiedName,
247 },
248
249 #[error("Symbol {what} (aliased from {alias}) is private from within {within}")]
251 SymbolBehindAliasIsPrivate {
252 what: QualifiedName,
254 alias: QualifiedName,
256 within: QualifiedName,
258 },
259
260 #[error("Unused global symbol {0}.")]
262 UnusedGlobalSymbol(String),
263
264 #[error("Unused local {0}.")]
266 UnusedLocal(Identifier),
267
268 #[error("Evaluation aborted because of prior resolve errors!")]
270 ResolveFailed,
271
272 #[error("Bad range, first number ({0}) must be smaller than last ({1})")]
274 BadRange(i64, i64),
275}
276
277pub type EvalResult<T> = std::result::Result<T, EvalError>;
279
280impl From<ResolveError> for EvalError {
281 fn from(err: ResolveError) -> Self {
282 match err {
283 ResolveError::SymbolNotFound(name) => EvalError::SymbolNotFound(name),
284 other => EvalError::ResolveError(other),
285 }
286 }
287}