feat: typechecking is working
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
||||
};
|
||||
|
||||
use aiken_lang::{error::ParseError, tipo};
|
||||
use miette::{EyreContext, LabeledSpan, MietteHandlerOpts, RgbColors, SourceCode};
|
||||
use miette::{Diagnostic, EyreContext, LabeledSpan, MietteHandlerOpts, RgbColors, SourceCode};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(thiserror::Error)]
|
||||
@@ -27,7 +27,7 @@ pub enum Error {
|
||||
#[error("a list of errors")]
|
||||
List(Vec<Self>),
|
||||
|
||||
#[error("failed to parse")]
|
||||
#[error("parsing")]
|
||||
Parse {
|
||||
path: PathBuf,
|
||||
|
||||
@@ -37,10 +37,11 @@ pub enum Error {
|
||||
error: Box<ParseError>,
|
||||
},
|
||||
|
||||
#[error("type checking failed")]
|
||||
#[error("type checking")]
|
||||
Type {
|
||||
path: PathBuf,
|
||||
src: String,
|
||||
#[source]
|
||||
error: tipo::error::Error,
|
||||
},
|
||||
}
|
||||
@@ -52,6 +53,10 @@ impl Error {
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report(&self) {
|
||||
eprintln!("Error: {:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Error {
|
||||
@@ -73,7 +78,7 @@ impl Debug for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl miette::Diagnostic for Error {
|
||||
impl Diagnostic for Error {
|
||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||
match self {
|
||||
Error::DuplicateModule { .. } => Some(Box::new("aiken::module::duplicate")),
|
||||
@@ -99,7 +104,7 @@ impl miette::Diagnostic for Error {
|
||||
))),
|
||||
Error::List(_) => None,
|
||||
Error::Parse { error, .. } => error.kind.help(),
|
||||
Error::Type { .. } => None,
|
||||
Error::Type { error, .. } => error.help(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,3 +130,62 @@ impl miette::Diagnostic for Error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, thiserror::Error)]
|
||||
pub enum Warning {
|
||||
#[error("type checking")]
|
||||
Type {
|
||||
path: PathBuf,
|
||||
src: String,
|
||||
#[source]
|
||||
warning: tipo::error::Warning,
|
||||
},
|
||||
}
|
||||
|
||||
impl Diagnostic for Warning {
|
||||
fn source_code(&self) -> Option<&dyn SourceCode> {
|
||||
match self {
|
||||
Warning::Type { src, .. } => Some(src),
|
||||
}
|
||||
}
|
||||
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
||||
match self {
|
||||
Warning::Type { warning, .. } => warning.labels(),
|
||||
}
|
||||
}
|
||||
|
||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||
match self {
|
||||
Warning::Type { .. } => Some(Box::new("aiken::typecheck")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Warning {
|
||||
pub fn from_type_warning(warning: tipo::error::Warning, path: PathBuf, src: String) -> Warning {
|
||||
Warning::Type { path, warning, src }
|
||||
}
|
||||
|
||||
pub fn report(&self) {
|
||||
eprintln!("Warning: {:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Warning {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let miette_handler = MietteHandlerOpts::new()
|
||||
// For better support of terminal themes use the ANSI coloring
|
||||
.rgb_colors(RgbColors::Never)
|
||||
// If ansi support is disabled in the config disable the eye-candy
|
||||
.color(true)
|
||||
.unicode(true)
|
||||
.terminal_links(true)
|
||||
.build();
|
||||
|
||||
// Ignore error to prevent format! panics. This can happen if span points at some
|
||||
// inaccessible location, for example by calling `report_error()` with wrong working set.
|
||||
let _ = miette_handler.debug(self, f);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ fn main() -> miette::Result<()> {
|
||||
let build_result = project.build();
|
||||
|
||||
for warning in project.warnings {
|
||||
eprintln!("Warning: {:?}", warning)
|
||||
warning.report()
|
||||
}
|
||||
|
||||
if let Err(err) = build_result {
|
||||
@@ -65,7 +65,7 @@ fn main() -> miette::Result<()> {
|
||||
rest => eprintln!("Error: {:?}", rest),
|
||||
}
|
||||
|
||||
miette::bail!("failed: {} errors", err.total());
|
||||
// miette::bail!("failed: {} errors", err.total());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,11 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use aiken_lang::{
|
||||
ast::ModuleKind,
|
||||
builtins,
|
||||
tipo::{self, TypeInfo},
|
||||
IdGenerator,
|
||||
};
|
||||
use aiken_lang::{ast::ModuleKind, builtins, tipo::TypeInfo, IdGenerator};
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
error::Error,
|
||||
error::{Error, Warning},
|
||||
module::{CheckedModule, ParsedModule, ParsedModules},
|
||||
};
|
||||
|
||||
@@ -25,21 +20,6 @@ pub struct Source {
|
||||
pub kind: ModuleKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Warning {
|
||||
Type {
|
||||
path: PathBuf,
|
||||
src: String,
|
||||
warning: tipo::error::Warning,
|
||||
},
|
||||
}
|
||||
|
||||
impl Warning {
|
||||
pub fn from_type_warning(warning: tipo::error::Warning, path: PathBuf, src: String) -> Warning {
|
||||
Warning::Type { path, warning, src }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Project {
|
||||
config: Config,
|
||||
defined_modules: HashMap<String, PathBuf>,
|
||||
|
||||
Reference in New Issue
Block a user