swamp_analyzer/
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 source_map_node::Node;
6use std::num::{ParseFloatError, ParseIntError};
7use swamp_semantic::SemanticError;
8use swamp_types::prelude::*;
9
10#[derive(Debug)]
11pub struct Error {
12    pub node: Node,
13    pub kind: ErrorKind,
14}
15#[derive(Debug)]
16pub enum ErrorKind {
17    NoAssociatedFunction(Type, String),
18    MissingSubscriptMember,
19    UnusedVariablesCanNotBeMut,
20    VariableTypeMustBeConcrete,
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(Type),
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 { expected: Type, found: Type },
49    MapValueTypeMismatch { expected: Type, found: Type },
50    IncompatibleTypes { expected: Type, found: Type },
51    UnknownMemberFunction,
52    ExpressionsNotAllowedInLetPattern,
53    UnknownField,
54    EnumVariantHasNoFields,
55    TooManyTupleFields { max: usize, got: usize },
56    ExpectedBooleanExpression,
57    NotAnIterator,
58    IntConversionError(ParseIntError),
59    FloatConversionError(ParseFloatError),
60    BoolConversionError,
61    DuplicateFieldInStructInstantiation(String),
62    UnknownIdentifier(String),
63    NoDefaultImplemented(Type),
64    UnknownConstant,
65    NotValidLocationStartingPoint,
66    CallsCanNotBePartOfChain,
67    UnwrapCanNotBePartOfChain,
68    NoneCoalesceCanNotBePartOfChain,
69    SelfNotCorrectType,
70    CanNotNoneCoalesce,
71    UnknownSymbol,
72    UnknownEnumType,
73    UnknownModule,
74    BreakOutsideLoop,
75    ReturnOutsideCompare,
76    EmptyMatch,
77    MatchArmsMustHaveTypes,
78    ContinueOutsideLoop,
79    ParameterIsNotMutable,
80    CouldNotCoerceTo(Type),
81    UnexpectedType,
82    CanNotAttachFunctionsToType,
83    MissingMemberFunction(String),
84    ExpectedLambda,
85}
86
87impl From<SemanticError> for Error {
88    fn from(value: SemanticError) -> Self {
89        Self {
90            node: Default::default(),
91            kind: ErrorKind::SemanticError(value),
92        }
93    }
94}