[Analyser]
Add a type error struct for when we add TypeChecker specific errors
Move generic functons from ResolverError  to AnalyserError
use thiserror::Error;
use noirc_errors::CustomDiagnostic as Diagnostic;
use noirc_errors::DiagnosableError;
-use noirc_errors::Span;
-use crate::ast::{Ident, Expression};
+pub use noirc_errors::Span;
+use crate::ast::{Ident, Expression, Type};
#[derive(Error, Debug)]
pub enum ResolverError {
@@ -12,17 +12,6 @@ pub enum ResolverError {
UnusedVariables { span: Span, ident : String},
#[error("Could not find symbol in this scope")]
Unresolved { span: Span, symbol_type : String, symbol : String},
- #[error("Unstructured")]
- Unstructured { span: Span, message : String},
-}
-
-impl ResolverError {
- pub fn from_ident(message : String, ident: &Ident) -> ResolverError {
- ResolverError::Unstructured{message, span :ident.0.span() }
- }
- pub fn from_expression(message : String, expr: &Expression) -> ResolverError {
- ResolverError::Unstructured{message, span :expr.span }
- }
}
impl Into<AnalyserError> for ResolverError {
@@ -46,12 +35,6 @@ impl DiagnosableError for ResolverError {
span : *span
}
}
- ResolverError::Unstructured {span, message} => {
- Diagnostic{
- message : message.to_string(),
- span : *span
- }
- }
ResolverError::Unresolved {span, symbol_type, symbol} => {
Diagnostic{
message : format!("cannot find {} `{}` in this scope ", symbol_type, symbol),
@@ -62,19 +45,35 @@ impl DiagnosableError for ResolverError {
}
}
+#[derive(Error, Debug)]
+pub enum TypeError {
+
+}
+
+impl DiagnosableError for TypeError {
+ fn to_diagnostic(&self) -> Diagnostic{
+ todo!()
+ }
+}
+
+
+
#[derive(Error, Debug)]
pub enum AnalyserError {
#[error("Resolver Error")]
ResolverError(ResolverError),
- #[error("Unstructured Error")]
- UnstructuredError { span: Span, message : String},
+ #[error("Type Error")]
+ TypeError(TypeError),
+ #[error("Unstructured")]
+ Unstructured { span: Span, message : String},
}
impl DiagnosableError for AnalyserError {
fn to_diagnostic(&self) -> Diagnostic{
match self {
AnalyserError::ResolverError(res) => res.to_diagnostic(),
- AnalyserError::UnstructuredError{span, message} => {
+ AnalyserError::TypeError(res) => res.to_diagnostic(),
+ AnalyserError::Unstructured{span, message} => {
Diagnostic{
message : message.to_string(),
span : *span
@@ -83,3 +82,12 @@ impl DiagnosableError for AnalyserError {
}
}
}
+
+impl AnalyserError {
+ pub fn from_ident(message : String, ident: &Ident) -> AnalyserError {
+ AnalyserError::Unstructured{message, span :ident.0.span() }
+ }
+ pub fn from_expression(message : String, expr: &Expression) -> AnalyserError {
+ AnalyserError::Unstructured{message, span :expr.span }
+ }
+}
\ No newline at end of file
