feat: implement semantic check for a function declaration

master
Araozu 2024-08-27 10:15:04 -05:00
parent b481351597
commit 46758f1ddf
3 changed files with 16 additions and 6 deletions

2
Cargo.lock generated
View File

@ -92,7 +92,7 @@ dependencies = [
[[package]] [[package]]
name = "thp" name = "thp"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"colored", "colored",
"serde", "serde",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "thp" name = "thp"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"

View File

@ -37,14 +37,24 @@ impl SemanticCheck for FunctionDeclaration<'_> {
return Err(err); return Err(err);
} }
} }
BlockMember::Stmt(Statement::FnDecl(_)) => { BlockMember::Stmt(Statement::FnDecl(f)) => {
todo!("Function declaration: semantic check not implemented") // TODO: (for now) a function cannot be declared inside another function.
let error = SemanticError {
error_start: f.identifier.position,
error_end: f.identifier.get_end_position(),
reason: format!(
"A function cannot be defined inside another function."
),
};
return Err(MistiError::Semantic(error));
} }
_ => todo!("Expression: semantic check not implemented"), BlockMember::Expr(e) => e.check_semantics(scope)?,
} }
} }
// TODO: Check the return type of the function // TODO: Check that the return type of the function
// matches the return type of the last expression
scope.insert(function_name, Type::Function(vec![], "Unit".into())); scope.insert(function_name, Type::Function(vec![], "Unit".into()));