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 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    CanNotDestructure,
30    UnknownStructTypeReference,
31    DuplicateFieldName,
32    MissingFieldInStructInstantiation(Vec<String>, AnonymousStructType),
33    UnknownVariable,
34    ArrayIndexMustBeInt(Type),
35    OverwriteVariableWithAnotherType,
36    NoneNeedsExpectedTypeHint,
37    ExpectedMutableLocation,
38    WrongNumberOfArguments(usize, usize),
39    CanOnlyOverwriteVariableWithMut,
40    OverwriteVariableNotAllowedHere,
41    UnknownEnumVariantType,
42    UnknownStructField,
43    UnknownEnumVariantTypeInPattern,
44    ExpectedEnumInPattern,
45    WrongEnumVariantContainer(EnumVariantType),
46    VariableIsNotMutable,
47    ArgumentIsNotMutable,
48    UnknownTypeReference,
49    SemanticError(SemanticError),
50    ExpectedOptional,
51    MapKeyTypeMismatch { expected: Type, found: Type },
52    MapValueTypeMismatch { expected: Type, found: Type },
53    IncompatibleTypes(Type, Type),
54    UnknownMemberFunction,
55    ExpressionsNotAllowedInLetPattern,
56    UnknownField,
57    EnumVariantHasNoFields,
58    TooManyTupleFields { max: usize, got: usize },
59    ExpectedBooleanExpression,
60    NotAnIterator,
61    IntConversionError(ParseIntError),
62    FloatConversionError(ParseFloatError),
63    BoolConversionError,
64    DuplicateFieldInStructInstantiation(String),
65    UnknownFunction,
66    NoDefaultImplemented(Type),
67    UnknownConstant,
68    NotValidLocationStartingPoint,
69    CallsCanNotBePartOfChain,
70    UnwrapCanNotBePartOfChain,
71    NoneCoalesceCanNotBePartOfChain,
72    SelfNotCorrectType,
73    CanNotNoneCoalesce,
74    UnknownSymbol,
75    UnknownEnumType,
76    UnknownModule,
77    BreakOutsideLoop,
78    ReturnOutsideCompare,
79    EmptyMatch,
80    MatchArmsMustHaveTypes,
81    ContinueOutsideLoop,
82    ParameterIsNotMutable,
83    CouldNotCoerceTo(Type),
84    UnexpectedType,
85    CanNotAttachFunctionsToType,
86    MissingMemberFunction(String),
87}
88
89impl From<SemanticError> for Error {
90    fn from(value: SemanticError) -> Self {
91        Self {
92            node: Default::default(),
93            kind: ErrorKind::SemanticError(value),
94        }
95    }
96}