-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy patherrors.rs
More file actions
112 lines (88 loc) · 3.2 KB
/
errors.rs
File metadata and controls
112 lines (88 loc) · 3.2 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use thiserror::Error;
use crate::ast::{Pattern, Term, Universe};
use crate::context::ContextError;
use crate::lexer::LexicalError;
use crate::unification::UnificationError;
/// Unified error type for the COC implementation
#[derive(Debug, Error)]
pub enum CocError {
#[error("Lexical error: {0}")]
Lexical(#[from] LexicalError),
#[error("Parse error: {0}")]
Parse(#[from] ParseError),
#[error("Type error: {0}")]
Type(#[from] TypeError),
#[error("IO error: {0}")]
IO(#[from] std::io::Error),
}
/// Type checking errors with detailed context
#[derive(Debug, Error, Clone)]
pub enum TypeError {
#[error("Context error: {0}")]
Context(#[from] ContextError),
#[error("Unification error: {0}")]
Unification(#[from] UnificationError),
#[error("Expected function type, got {term} : {ty}")]
NotAFunction { term: Term, ty: Term },
#[error("Expected type, got {term} : {ty}")]
NotAType { term: Term, ty: Term },
#[error("Type mismatch: expected {expected}, got {actual}")]
TypeMismatch { expected: Term, actual: Term },
#[error("Universe error: {universe}")]
UniverseError { universe: Universe },
#[error("Invalid inductive type '{name}': {reason}")]
InvalidInductive { name: String, reason: String },
#[error("Pattern {pattern} cannot match type {term_type}")]
PatternMatchError { pattern: Pattern, term_type: Term },
#[error("Missing case for pattern {pattern}")]
MissingCase { pattern: Pattern },
// More specific error types
#[error("Unknown constructor '{name}'")]
UnknownConstructor { name: String },
#[error("Constructor '{name}' expects {expected} arguments, got {actual}")]
ConstructorArityMismatch {
name: String,
expected: usize,
actual: usize,
},
#[error("Field '{field}' not found for type '{ty}'")]
FieldNotFound { field: String, ty: Term },
#[error("Cannot project field '{field}' from non-structure type '{ty}'")]
InvalidProjection { field: String, ty: Term },
#[error("Match expression must have at least one arm")]
EmptyMatch,
#[error("Unexpected implicit parameter '{param}' after processing")]
UnexpectedImplicitParameter { param: String },
#[error("Internal compiler error: {message}")]
Internal { message: String },
#[error("While type-checking expression: {expr}\n{source}")]
WithContext {
expr: Term,
#[source]
source: Box<TypeError>,
},
}
/// Parse errors
#[derive(Debug, Error, Clone)]
pub enum ParseError {
#[error("Unexpected token '{token}', expected one of: {}", expected.join(", "))]
UnexpectedToken {
token: String,
expected: Vec<String>,
location: Option<(usize, usize)>, // (start, end)
},
#[error("Unexpected end of input, expected one of: {}", expected.join(", "))]
UnexpectedEndOfInput {
expected: Vec<String>,
location: Option<usize>,
},
#[error("Invalid syntax: {message}")]
InvalidSyntax {
message: String,
location: Option<usize>,
},
#[error("Lexical error: {0}")]
LexicalError(#[from] LexicalError),
}
pub type CocResult<T> = Result<T, CocError>;
pub type TypeResult<T> = Result<T, TypeError>;