Improved semantic errors
This commit is contained in:
@@ -186,7 +186,7 @@ fn is_source_newer(source *Path, output *Path) std::io::Result<bool> {
|
||||
|
||||
pub enum TranspileError<'a> {
|
||||
Parse[error::ParseError<'a, Vec<mist_parser::ast::TopLevel>>],
|
||||
Semantic[mist_parser::semantics::SemanticError]
|
||||
Semantic[Vec<mist_parser::semantics::SemanticError>]
|
||||
}
|
||||
|
||||
pub fn transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>)
|
||||
@@ -262,15 +262,17 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
||||
let curr_dir = std::env::current_dir().unwrap();
|
||||
|
||||
match err {
|
||||
TranspileError::Semantic[e] => {
|
||||
TranspileError::Semantic[e_list] => {
|
||||
for e in e_list {
|
||||
eprintln!(
|
||||
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}",
|
||||
path.strip_prefix(curr_dir).unwrap_or_else(|_| path).as_os_str().display(),
|
||||
path.strip_prefix(&curr_dir).unwrap_or_else(|_| path).as_os_str().display(),
|
||||
e.line,
|
||||
e.column,
|
||||
e.error_message,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TranspileError::Parse[e] => {
|
||||
match e {
|
||||
|
||||
@@ -33,11 +33,12 @@ pub fn find_function_call<'a>(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn check_class_semantics<'a>(top_level: &TopLevel) -> Result<(), SemanticError> {
|
||||
pub fn check_class_semantics<'a>(top_level: &TopLevel) -> Result<(), Vec<SemanticError>> {
|
||||
if let TopLevelKind::ClassDecl {
|
||||
fields,
|
||||
constructor,
|
||||
items,
|
||||
name,
|
||||
..
|
||||
} = &top_level.0.item
|
||||
{
|
||||
@@ -63,15 +64,24 @@ pub fn check_class_semantics<'a>(top_level: &TopLevel) -> Result<(), SemanticErr
|
||||
|
||||
let mut mutability_iter = mutability.into_iter();
|
||||
|
||||
let mut errs = Vec::new();
|
||||
|
||||
for field in &fields {
|
||||
if mutability_iter.find(|v| v == &field.item).is_none() {
|
||||
return Err(SemanticError {
|
||||
errs.push(SemanticError {
|
||||
line: field.line,
|
||||
column: field.column,
|
||||
error_message: format!("Field `{}` is uninitialized", field.item.0),
|
||||
error_message: format!(
|
||||
"class field `{}.{}` is uninitialized",
|
||||
name.0, field.item.0
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if errs.len() > 0 {
|
||||
return Err(errs);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user