From ecfff0ac0dd768dc55acd8da2275567dbe3ae231 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 16 Jun 2026 15:37:34 +0200 Subject: [PATCH] Improved semantic errors --- crates/mist-api/src/transpiler.mist | 20 +++++++++++--------- crates/parser/src/semantics.rs | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 992b3f1..f7001ea 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -186,7 +186,7 @@ fn is_source_newer(source *Path, output *Path) std::io::Result { pub enum TranspileError<'a> { Parse[error::ParseError<'a, Vec>], - Semantic[mist_parser::semantics::SemanticError] + Semantic[Vec] } 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,14 +262,16 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { let curr_dir = std::env::current_dir().unwrap(); match err { - TranspileError::Semantic[e] => { - eprintln!( - "\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}", - path.strip_prefix(curr_dir).unwrap_or_else(|_| path).as_os_str().display(), - e.line, - e.column, - e.error_message, - ); + 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(), + e.line, + e.column, + e.error_message, + ); + } } TranspileError::Parse[e] => { diff --git a/crates/parser/src/semantics.rs b/crates/parser/src/semantics.rs index fa369ae..3cfccbe 100644 --- a/crates/parser/src/semantics.rs +++ b/crates/parser/src/semantics.rs @@ -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> { 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(())