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