swamp_semantic/
err.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5use crate::SemanticError;
6use source_map_node::Node;
7use std::num::{ParseFloatError, ParseIntError};
8use swamp_types::prelude::*;
9
10#[derive(Clone, Debug)]
11pub struct Error {
12    pub node: Node,
13    pub kind: ErrorKind,
14}
15#[derive(Clone, Debug)]
16pub enum ErrorKind {
17    NoAssociatedFunction(TypeRef, String),
18    MissingSubscriptMember,
19    UnusedVariablesCanNotBeMut,
20    VariableTypeMustBeBlittable(TypeRef),
21    GuardCanNotHaveMultipleWildcards,
22    WildcardMustBeLastInGuard,
23    GuardMustHaveWildcard,
24    GuardHasNoType,
25    TooManyDestructureVariables,
26    CanNotDestructure,
27    UnknownStructTypeReference,
28    DuplicateFieldName,
29    MissingFieldInStructInstantiation(Vec<String>, AnonymousStructType),
30    UnknownVariable,
31    ArrayIndexMustBeInt(TypeRef),
32    OverwriteVariableWithAnotherType,
33    NoneNeedsExpectedTypeHint,
34    ExpectedMutableLocation,
35    WrongNumberOfArguments(usize, usize),
36    CanOnlyOverwriteVariableWithMut,
37    OverwriteVariableNotAllowedHere,
38    UnknownEnumVariantType,
39    UnknownStructField,
40    UnknownEnumVariantTypeInPattern,
41    ExpectedEnumInPattern,
42    WrongEnumVariantContainer(EnumVariantType),
43    VariableIsNotMutable,
44    ArgumentIsNotMutable,
45    UnknownTypeReference,
46    SemanticError(SemanticError),
47    ExpectedOptional,
48    MapKeyTypeMismatch {
49        expected: TypeRef,
50        found: TypeRef,
51    },
52    MapValueTypeMismatch {
53        expected: TypeRef,
54        found: TypeRef,
55    },
56    IncompatibleTypes {
57        expected: TypeRef,
58        found: TypeRef,
59    },
60    UnknownMemberFunction(TypeRef),
61    ExpressionsNotAllowedInLetPattern,
62    UnknownField,
63    EnumVariantHasNoFields,
64    TooManyTupleFields {
65        max: usize,
66        got: usize,
67    },
68    ExpectedBooleanExpression,
69    NotAnIterator,
70    IntConversionError(ParseIntError),
71    FloatConversionError(ParseFloatError),
72    BoolConversionError,
73    DuplicateFieldInStructInstantiation(String),
74    UnknownIdentifier(String),
75    NoDefaultImplemented(TypeRef),
76    UnknownConstant,
77    NotValidLocationStartingPoint,
78    CallsCanNotBePartOfChain,
79    UnwrapCanNotBePartOfChain,
80    NoneCoalesceCanNotBePartOfChain,
81    OptionalChainingOperatorCanNotBePartOfChain,
82    SelfNotCorrectType,
83    CanNotNoneCoalesce,
84    UnknownSymbol,
85    UnknownEnumType,
86    UnknownModule,
87    BreakOutsideLoop,
88    ReturnOutsideCompare,
89    EmptyMatch,
90    MatchArmsMustHaveTypes,
91    ContinueOutsideLoop,
92    ParameterIsNotMutable,
93    CouldNotCoerceTo(TypeRef),
94    UnexpectedType,
95    CanNotAttachFunctionsToType,
96    MissingMemberFunction(String, TypeRef),
97    ExpectedLambda,
98    ExpectedSlice,
99    MissingToString(TypeRef),
100    IncompatibleTypesForAssignment {
101        expected: TypeRef,
102        found: TypeRef,
103    },
104    CapacityNotEnough {
105        size_requested: usize,
106        capacity: usize,
107    },
108    ExpectedInitializerTarget {
109        destination_type: TypeRef,
110    },
111    NoInferredTypeForEmptyInitializer,
112    TooManyInitializerListElementsForStorage {
113        capacity: usize,
114    },
115    KeyVariableNotAllowedToBeMutable,
116    SelfNotCorrectMutableState,
117    NotAllowedAsReturnType(TypeRef),
118    ParameterTypeCanNotBeStorage(TypeRef),
119    OperatorProblem,
120    MatchMustHaveAtLeastOneArm,
121    NeedStorage,
122    TooManyParameters {
123        encountered: usize,
124        allowed: usize,
125    },
126}
127
128impl From<SemanticError> for Error {
129    fn from(value: SemanticError) -> Self {
130        Self {
131            node: Node::default(),
132            kind: ErrorKind::SemanticError(value),
133        }
134    }
135}