feat: implement semantic check for a function declaration
This commit is contained in:
parent
b481351597
commit
46758f1ddf
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "thp"
|
name = "thp"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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()));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user