1use seq_map::SeqMapError;
7use std::num::{ParseFloatError, ParseIntError};
8use swamp_script_semantic::{
9 AnonymousStructType, EnumVariantTypeRef, Node, SemanticError, Span, StructTypeRef, Type,
10};
11
12#[derive(Debug)]
13pub struct Error {
14 pub node: Node,
15 pub kind: ErrorKind,
16}
17#[derive(Debug)]
18pub enum ErrorKind {
19 UnusedVariablesCanNotBeMut,
20 UnknownIdentifier,
21 VariableTypeMustBeConcrete,
22 GuardCanNotHaveMultipleWildcards,
23 WildcardMustBeLastInGuard,
24 GuardMustHaveWildcard,
25 GuardHasNoType,
26 TooManyDestructureVariables,
27 EmptyBlockWrongType,
28 CanNotDestructure,
29 EmptyArrayCanOnlyBeMapOrArray,
30 CanNotFindModule(Vec<String>),
32 UnknownStructTypeReference,
33 UnknownLocalStructTypeReference(swamp_script_ast::LocalTypeIdentifier),
34 DuplicateFieldName,
35 Unknown(String),
36 UnknownImplTargetTypeReference(swamp_script_ast::LocalTypeIdentifier),
37 WrongFieldCountInStructInstantiation(StructTypeRef, usize),
38 MissingFieldInStructInstantiation(Vec<String>, AnonymousStructType),
39 ExpectedFunctionExpression,
40 CouldNotFindMember(Node, Node),
41 UnknownVariable,
42 NotAnArray,
43 ArrayIndexMustBeInt(Type),
44 OverwriteVariableWithAnotherType,
45 NoneNeedsExpectedTypeHint,
46 ExpectedMutableLocation,
47 WrongNumberOfArguments(usize, usize),
48 IncompatibleArguments(Type, Type),
49 CanOnlyOverwriteVariableWithMut,
50 OverwriteVariableNotAllowedHere,
51 NotNamedStruct(Type),
52 UnknownEnumVariantType,
53 WasNotStructType,
54 UnknownStructField,
55 MustBeEnumType(swamp_script_ast::Pattern),
56 UnknownEnumVariantTypeInPattern,
57 ExpectedEnumInPattern,
58 WrongEnumVariantContainer(EnumVariantTypeRef),
59 VariableIsNotMutable,
60 ArgumentIsNotMutable,
61 WrongNumberOfTupleDeconstructVariables,
62 UnknownTypeReference,
63 SemanticError(SemanticError),
64 SeqMapError(SeqMapError),
65 ExpectedMemberCall,
66 CouldNotFindStaticMember(Node, Node),
67 TypeAliasNotAStruct,
68 ModuleNotUnique,
69 ExpressionIsOfWrongFieldType(Span, Type, Type),
70 ExpectedOptional,
71 ExpectedVariable,
72 EmptyMapLiteral,
73 MapKeyTypeMismatch { expected: Type, found: Type },
74 MapValueTypeMismatch { expected: Type, found: Type },
75 TypeIsNotAnIndexCollection(Type),
76 NotSameKeyTypeForMapIndex(Type, Type),
77 UnknownIndexAwareCollection,
78 InvalidOperatorForArray,
79 IncompatibleTypes(Type, Type),
80 ExpectedArray(Type),
81 UnknownMemberFunction,
82 WrongNumberOfTypeArguments(usize, i32),
83 OnlyVariablesAllowedInEnumPattern,
84 ExpressionsNotAllowedInLetPattern,
85 UnknownField,
86 EnumVariantHasNoFields,
87 TooManyTupleFields { max: usize, got: usize },
88 NotInFunction,
89 ExpectedBooleanExpression,
90 NotAnIterator,
91 UnsupportedIteratorPairs,
92 NeedStructForFieldLookup,
93 IntConversionError(ParseIntError),
94 FloatConversionError(ParseFloatError),
95 BoolConversionError,
96 DuplicateFieldInStructInstantiation(String),
97 InternalError(&'static str),
98 WasNotFieldMutRef,
99 UnknownFunction,
100 NoDefaultImplemented(Type),
101 NoDefaultImplementedForStruct(StructTypeRef),
102 UnknownConstant,
103 ExpectedFunctionTypeForFunctionCall,
104 TypeDoNotSupportIndexAccess,
105 NoneCoalesceNeedsOptionalType,
106 TypeDoNotSupportRangeAccess,
107 ArgumentMustBeImmutable,
108 NotValidLocationStartingPoint,
109 NotValidLocationItem,
110 ExpectedImmutableExpression,
111 CallsCanNotBePartOfChain,
112 UnwrapCanNotBePartOfChain,
113 NoneCoalesceCanNotBePartOfChain,
114 SelfNotCorrectType,
115 IllegalIndexInChain,
116 CanNotNoneCoalesce,
117 UnknownSymbol,
118 UnknownEnumType,
119 UnknownModule,
120 BreakOutsideLoop,
121 ReturnOutsideCompare,
122 EmptyMatch,
123 MatchArmsMustHaveTypes,
124 ContinueOutsideLoop,
125 ParameterIsNotMutable,
126}
127
128impl From<SemanticError> for Error {
129 fn from(value: SemanticError) -> Self {
130 Self {
131 node: Default::default(),
132 kind: ErrorKind::SemanticError(value),
133 }
134 }
135}