summaryrefslogtreecommitdiffstats
path: root/crates/rebel-lang/src/typing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rebel-lang/src/typing.rs')
-rw-r--r--crates/rebel-lang/src/typing.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs
index 59c161b..5309e76 100644
--- a/crates/rebel-lang/src/typing.rs
+++ b/crates/rebel-lang/src/typing.rs
@@ -78,6 +78,19 @@ impl Type {
})
}
+ pub fn ast_stmt_type(ctx: &Context, expr: &ast::BodyStmt<'_>) -> Result<Type> {
+ match expr {
+ ast::BodyStmt::Assign { dest: _, expr } => {
+ // TODO: Assignability, dest type
+ let dest_type = Type::Free;
+ let expr_type = Self::ast_expr_type(ctx, expr)?;
+ dest_type.unify(expr_type, Coerce::Assign)
+ }
+ ast::BodyStmt::Expr { expr } => Self::ast_expr_type(ctx, expr),
+ ast::BodyStmt::Empty => Ok(Type::Unit),
+ }
+ }
+
pub fn ast_expr_type(ctx: &Context, expr: &ast::Expr<'_>) -> Result<Type> {
use ast::Expr::*;