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 {1}.")]
54 SymbolCannotBeCalled(QualifiedName, Box<SymbolDefinition>),
55
56 #[error("Ambiguous symbol {ambiguous} might be one of the following:\n{others}")]
58 AmbiguousSymbol {
59 ambiguous: QualifiedName,
61 others: Symbols,
63 },
64
65 #[error("Local symbol not found: {0}")]
67 LocalNotFound(Identifier),
68
69 #[error("Property not found: {0}")]
71 PropertyNotFound(Identifier),
72
73 #[error("Argument count mismatch: expected {expected}, got {found} in {args}")]
75 ArgumentCountMismatch {
76 args: ArgumentValueList,
78 expected: usize,
80 found: usize,
82 },
83
84 #[error("assert called with wrong number of arguments.")]
86 AssertWrongSignature(ArgumentValueList),
87
88 #[error("Invalid argument type: {0}")]
90 InvalidArgumentType(Type),
91
92 #[error("Unexpected argument: {0}: {1}")]
94 UnexpectedArgument(Identifier, Type),
95
96 #[error("Assertion failed: {0}")]
98 AssertionFailed(String),
99
100 #[error("Expected type `{expected}`, found type `{found}")]
102 ExpectedType {
103 expected: Type,
105 found: Type,
107 },
108
109 #[error("Error limit reached: Stopped evaluation after {0} errors")]
111 ErrorLimitReached(u32),
112
113 #[error("Local stack needed to store {0}")]
115 LocalStackEmpty(Identifier),
116
117 #[error("Unexpected stack frame of type '{1}' cannot store {0}")]
119 WrongStackFrame(Identifier, &'static str),
120
121 #[error("Value Error: {0}")]
123 ValueError(#[from] ValueError),
124
125 #[error("Unknown method `{0}`")]
127 UnknownMethod(QualifiedName),
128
129 #[error("Parsing error {0}")]
131 ParseError(#[from] ParseError),
132
133 #[error("{0} statement not available here")]
135 StatementNotSupported(&'static str),
136
137 #[error("Properties have not been initialized: {0}")]
139 UninitializedProperties(IdentifierList),
140
141 #[error("Unexpected {0} {1} within expression")]
143 UnexpectedNested(&'static str, Identifier),
144
145 #[error("No variables allowed in {0}")]
147 NoVariablesAllowedIn(&'static str),
148
149 #[error("Attribute error: {0}")]
151 AttributeError(#[from] AttributeError),
152
153 #[error("Missing arguments: {0}")]
155 MissingArguments(IdentifierList),
156
157 #[error("Too many arguments: {0}")]
159 TooManyArguments(IdentifierList),
160
161 #[error("Builtin error: {0}")]
163 BuiltinError(String),
164
165 #[error("Parameter not found by type '{0}'")]
167 ParameterByTypeNotFound(Type),
168
169 #[error("Multiplicity not allowed '{0}'")]
171 MultiplicityNotAllowed(IdentifierList),
172
173 #[error("Cannot mix 2d and 3d geometries")]
175 CannotMixGeometry,
176
177 #[error("If condition is not a boolean: {0}")]
179 IfConditionIsNotBool(Value),
180
181 #[error("Workbench {0} cannot find initialization for those arguments")]
183 NoInitializationFound(Identifier),
184
185 #[error("Workbench plan incomplete. Missing properties: {0}")]
187 BuildingPlanIncomplete(IdentifierList),
188
189 #[error("This expression statement did not produce any model")]
191 EmptyModelExpression,
192
193 #[error("The {0} workbench produced a 2D output, but expected {2} output.")]
195 WorkbenchInvalidOutput(WorkbenchKind, OutputType, OutputType),
196
197 #[error("The {0} workbench will produce no {1} output.")]
199 WorkbenchNoOutput(WorkbenchKind, OutputType),
200
201 #[error("Unexpected source file {0} in expression")]
203 InvalidSelfReference(Identifier),
204
205 #[error("Resolve error {0}")]
207 ResolveError(#[from] ResolveError),
208
209 #[error("{0} is not operation.")]
211 NotAnOperation(QualifiedName),
212
213 #[error("Calling operation on empty geometry")]
215 OperationOnEmptyGeometry,
216
217 #[error("Cannot call operation without workpiece.")]
219 CannotCallOperationWithoutWorkpiece,
220
221 #[error("Missing return statement in {0}")]
223 MissingReturn(QualifiedName),
224
225 #[error("Missing model in workbench")]
227 NoModelInWorkbench,
228
229 #[error("Found a symbol and a property with names {0} and {1}")]
231 AmbiguousProperty(QualifiedName, Identifier),
232
233 #[error("Value {0} already has been initialized with {1} (at line {2})")]
235 ValueAlreadyInitialized(Identifier, Value, SrcRef),
236
237 #[error("Assignment failed because {0} is not an l-value")]
239 NotAnLValue(Identifier),
240
241 #[error("Symbol {what} is private from within {within}")]
243 SymbolIsPrivate {
244 what: QualifiedName,
246 within: QualifiedName,
248 },
249
250 #[error("Symbol {what} (aliased from {alias}) is private from within {within}")]
252 SymbolBehindAliasIsPrivate {
253 what: QualifiedName,
255 alias: QualifiedName,
257 within: QualifiedName,
259 },
260}
261
262pub type EvalResult<T> = std::result::Result<T, EvalError>;