1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use crate::ir::IrValue;
use crate::shared::{ScopeError, ScopeErrorKind};
use crate::{QueryError, QueryErrorKind, ResolveError, ResolveErrorKind, Spanned};
use runestick::{AccessError, CompileMeta, SpannedError, TypeInfo, TypeOf};
use thiserror::Error;
error! {
#[derive(Debug)]
pub struct IrError {
kind: IrErrorKind,
}
impl From<ResolveError>;
impl From<QueryError>;
impl From<ScopeError>;
}
impl IrError {
pub fn expected<S, E>(spanned: S, actual: &IrValue) -> Self
where
S: Spanned,
E: TypeOf,
{
IrError::new(
spanned,
IrErrorKind::Expected {
expected: E::type_info(),
actual: actual.type_info(),
},
)
}
pub fn access<S>(spanned: S) -> impl FnOnce(AccessError) -> Self
where
S: Spanned,
{
move |error| Self::new(spanned, error)
}
}
impl From<IrError> for SpannedError {
fn from(error: IrError) -> Self {
SpannedError::new(error.span, *error.kind)
}
}
#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum IrErrorKind {
#[error("{message}")]
Custom { message: &'static str },
#[error("scope error: {error}")]
ScopeError {
#[source]
#[from]
error: ScopeErrorKind,
},
#[error("access error: {error}")]
AccessError {
#[source]
#[from]
error: AccessError,
},
#[error("{error}")]
QueryError {
#[source]
#[from]
error: Box<QueryErrorKind>,
},
#[error("{error}")]
ResolveError {
#[source]
#[from]
error: ResolveErrorKind,
},
#[error("expected a constant expression")]
NotConst,
#[error("constant cycle detected")]
ConstCycle,
#[error("{meta} is not supported here")]
UnsupportedMeta {
meta: CompileMeta,
},
#[error("expected a value of type {expected} but got {actual}")]
Expected {
expected: TypeInfo,
actual: TypeInfo,
},
#[error("evaluation budget exceeded")]
BudgetExceeded,
#[error("integer underflow")]
IntegerUnderflow,
#[error("missing index {index}")]
MissingIndex {
index: usize,
},
#[error("missing field `{field}`")]
MissingField {
field: Box<str>,
},
#[error("missing local `{name}`")]
MissingLocal {
name: Box<str>,
},
#[error("no constant or local matching `{name}`")]
MissingConst {
name: Box<str>,
},
#[error("break outside of supported loop")]
BreakOutsideOfLoop,
#[error("function not found")]
FnNotFound,
#[error("argument count mismatch, got {actual} but expected {expected}")]
ArgumentCountMismatch { actual: usize, expected: usize },
#[error("value `{value}` is outside of the supported integer range")]
NotInteger { value: num::BigInt },
}