swamp_script_analyzer/
err.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/script
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5
6use std::num::{ParseFloatError, ParseIntError};
7use swamp_script_node::Node;
8use swamp_script_semantic::SemanticError;
9use swamp_script_types::prelude::*;
10
11#[derive(Debug)]
12pub struct Error {
13    pub node: Node,
14    pub kind: ErrorKind,
15}
16#[derive(Debug)]
17pub enum ErrorKind {
18    NoAssociatedFunction(Type, String),
19    MissingSubscriptMember,
20    UnusedVariablesCanNotBeMut,
21    UnknownIdentifier,
22    VariableTypeMustBeConcrete,
23    GuardCanNotHaveMultipleWildcards,
24    WildcardMustBeLastInGuard,
25    GuardMustHaveWildcard,
26    GuardHasNoType,
27    TooManyDestructureVariables,
28    CanNotDestructure,
29    UnknownStructTypeReference,
30    DuplicateFieldName,
31    MissingFieldInStructInstantiation(Vec<String>, AnonymousStructType),
32    UnknownVariable,
33    ArrayIndexMustBeInt(Type),
34    OverwriteVariableWithAnotherType,
35    NoneNeedsExpectedTypeHint,
36    ExpectedMutableLocation,
37    WrongNumberOfArguments(usize, usize),
38    CanOnlyOverwriteVariableWithMut,
39    OverwriteVariableNotAllowedHere,
40    UnknownEnumVariantType,
41    UnknownStructField,
42    UnknownEnumVariantTypeInPattern,
43    ExpectedEnumInPattern,
44    WrongEnumVariantContainer(EnumVariantType),
45    VariableIsNotMutable,
46    ArgumentIsNotMutable,
47    UnknownTypeReference,
48    SemanticError(SemanticError),
49    ExpectedOptional,
50    MapKeyTypeMismatch { expected: Type, found: Type },
51    MapValueTypeMismatch { expected: Type, found: Type },
52    IncompatibleTypes { expected: Type, found: Type },
53    UnknownMemberFunction,
54    ExpressionsNotAllowedInLetPattern,
55    UnknownField,
56    EnumVariantHasNoFields,
57    TooManyTupleFields { max: usize, got: usize },
58    ExpectedBooleanExpression,
59    NotAnIterator,
60    IntConversionError(ParseIntError),
61    FloatConversionError(ParseFloatError),
62    BoolConversionError,
63    DuplicateFieldInStructInstantiation(String),
64    UnknownFunction,
65    NoDefaultImplemented(Type),
66    UnknownConstant,
67    NotValidLocationStartingPoint,
68    CallsCanNotBePartOfChain,
69    UnwrapCanNotBePartOfChain,
70    NoneCoalesceCanNotBePartOfChain,
71    SelfNotCorrectType,
72    CanNotNoneCoalesce,
73    UnknownSymbol,
74    UnknownEnumType,
75    UnknownModule,
76    BreakOutsideLoop,
77    ReturnOutsideCompare,
78    EmptyMatch,
79    MatchArmsMustHaveTypes,
80    ContinueOutsideLoop,
81    ParameterIsNotMutable,
82    CouldNotCoerceTo(Type),
83    UnexpectedType,
84    CanNotAttachFunctionsToType,
85    MissingMemberFunction(String),
86}
87
88impl From<SemanticError> for Error {
89    fn from(value: SemanticError) -> Self {
90        Self {
91            node: Default::default(),
92            kind: ErrorKind::SemanticError(value),
93        }
94    }
95}