roan_error/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use crate::{frame::Frame, span::TextSpan};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum RoanError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
    #[error("Invalid token: {0}")]
    InvalidToken(String, TextSpan),
    #[error("Expected {0}.")]
    ExpectedToken(String, String, TextSpan),
    #[error("Unexpected token: {0}")]
    UnexpectedToken(String, TextSpan),
    #[error("{0}")]
    SemanticError(String, TextSpan),
    #[error("Semantic error: {0}")]
    ResolverError(String),
    #[error("{0}")]
    ModuleError(String),
    #[error("Tried to import a item that does not exist: {0}")]
    ImportError(String, TextSpan),
    #[error("Failed to import {0}. {1}")]
    FailedToImportModule(String, String, TextSpan),
    #[error("Couldn't find variable: {0}")]
    VariableNotFoundError(String, TextSpan),
    #[error("Call to undefined function: {0}")]
    UndefinedFunctionError(String, TextSpan),
    #[error("Found normal parameter after rest parameter.")]
    RestParameterNotLast(TextSpan),
    #[error("Found rest parameter in non-last position.")]
    RestParameterNotLastPosition(TextSpan),
    #[error("Found more than one rest parameter.")]
    MultipleRestParameters(TextSpan),
    #[error("{0}")]
    Throw(String, Vec<Frame>),
    #[error("Invalid escape sequence: {0}")]
    InvalidEscapeSequence(String, TextSpan),
    #[error("{0} does not evaluate to a boolean.")]
    NonBooleanCondition(String, TextSpan),
    #[error("Index out of bounds: {0} >= {1}")]
    IndexOutOfBounds(usize, usize, TextSpan),
    #[error("Type mismatch: {0}")]
    TypeMismatch(String, TextSpan),
    #[error("Invalid assignment {0}")]
    InvalidAssignment(String, TextSpan),
    #[error("Attempted to access non-existent property: {0}")]
    PropertyNotFoundError(String, TextSpan),
    #[error("Invalid property access")]
    InvalidPropertyAccess(TextSpan),
    #[error("Found break or continue statement outside of loop.")]
    InvalidBreakOrContinue(TextSpan),
    #[error("Break was used outside loop.")]
    LoopBreak(TextSpan),
    #[error("Continue was used outside loop.")]
    LoopContinue(TextSpan),
    #[error("Invalid spread operator usage.")]
    InvalidSpread(TextSpan),
    #[error("Found multiple 'self' parameters.")]
    MultipleSelfParameters(TextSpan),
    #[error("Found 'self' parameter in non-first position.")]
    SelfParameterNotFirst(TextSpan),
    #[error("Self parameter cannot be rest.")]
    SelfParameterCannotBeRest(TextSpan),
    #[error("Struct not found: {0}")]
    StructNotFoundError(String, TextSpan),
    #[error("Trait definition not found: {0}")]
    TraitNotFoundError(String, TextSpan),
    #[error("Struct {0} already implements trait {1}")]
    StructAlreadyImplementsTrait(String, String, TextSpan),
    #[error("Trait {0} doesn't implement required method")]
    TraitMethodNotImplemented(String, Vec<String>, TextSpan),
    #[error("Cannot assign value to static member")]
    StaticMemberAssignment(TextSpan),
    #[error("Attempted to access static member of non-struct type")]
    StaticMemberAccess(TextSpan),
    #[error("Only call expressions can be accessed in a static context")]
    StaticContext(TextSpan),
    #[error("Invalid unary operator: {0}")]
    InvalidUnaryOperation(String, TextSpan),
    #[error("Missing non-nullable parameter: {0}")]
    MissingParameter(String, TextSpan),
    #[error("Invalid type provided: {0}. Available types: {1}")]
    InvalidType(String, String, TextSpan),
}