semantic_analyzer/types/
error.rs1use crate::ast::CodeLocation;
5#[cfg(feature = "codec")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Eq, PartialEq)]
10#[cfg_attr(
11 feature = "codec",
12 derive(Serialize, Deserialize),
13 serde(tag = "type", content = "content")
14)]
15pub enum StateErrorKind {
16 Common,
18 ConstantAlreadyExist,
19 ConstantNotFound,
20 WrongLetType,
21 WrongExpressionType,
22 TypeAlreadyExist,
23 FunctionAlreadyExist,
24 ValueNotFound,
25 ValueNotStruct,
26 ValueNotStructField,
27 ValueIsNotMutable,
28 FunctionNotFound,
29 FunctionParameterTypeWrong,
30 ReturnNotFound,
31 ReturnAlreadyCalled,
32 IfElseDuplicated,
33 TypeNotFound,
34 WrongReturnType,
35 ConditionExpressionWrongType,
36 ConditionIsEmpty,
37 ConditionExpressionNotSupported,
38 ForbiddenCodeAfterReturnDeprecated,
39 ForbiddenCodeAfterContinueDeprecated,
40 ForbiddenCodeAfterBreakDeprecated,
41 FunctionArgumentNameDuplicated,
42}
43
44#[derive(Debug, Clone, Eq, PartialEq)]
46#[cfg_attr(feature = "codec", derive(Serialize, Deserialize))]
47pub struct StateErrorLocation(pub CodeLocation);
48
49#[derive(Debug, Clone, Eq, PartialEq)]
51#[cfg_attr(feature = "codec", derive(Serialize, Deserialize))]
52pub struct StateErrorResult {
53 pub kind: StateErrorKind,
55 pub value: String,
57 pub location: StateErrorLocation,
59}
60
61impl StateErrorResult {
62 #[must_use]
63 pub const fn new(kind: StateErrorKind, value: String, location: CodeLocation) -> Self {
64 Self {
65 kind,
66 value,
67 location: StateErrorLocation(location),
68 }
69 }
70}
71
72impl StateErrorResult {
73 #[must_use]
75 pub fn trace_state(&self) -> String {
76 format!(
77 "[{:?}] for value {:?} at: {:?}:{:?}",
78 self.kind,
79 self.value,
80 self.location.0.line(),
81 self.location.0.offset()
82 )
83 }
84}