Naive typechecking of binary operators

This commit is contained in:
Araozu 2024-05-06 09:53:18 -05:00
parent 4f7fa0f5e3
commit 7218898ce0

View File

@ -31,7 +31,25 @@ impl Typed for Expression<'_> {
} }
Expression::FunctionCall(_) => todo!(), Expression::FunctionCall(_) => todo!(),
Expression::UnaryOperator(_, _) => todo!(), Expression::UnaryOperator(_, _) => todo!(),
Expression::BinaryOperator(_, _, _) => todo!(), Expression::BinaryOperator(exp1, exp2, operator) => {
let t1 = exp1.get_type(scope)?;
let t2 = exp2.get_type(scope)?;
// TODO: There's definitely a better way to do this
if *operator == "+" && t1 == "Int" && t2 == "Int" {
return Ok("Int".into());
} else if *operator == "-" && t1 == "Int" && t2 == "Int" {
return Ok("Int".into());
}
return Err(MistiError::Semantic(SemanticError {
error_start: 0,
error_end: 1,
reason: format!(
"Unsupported binary operator or invalid arguments to the operator."
),
}));
}
} }
} }
} }