use crate::mir::expr::Expr;
use crate::source_span::Spanned;
#[derive(Debug, PartialEq, Eq)]
pub struct TypeCheckError {
msg: String,
}
impl TypeCheckError {
pub fn new(msg: String) -> Self {
Self { msg }
}
pub fn pretty_desc(&self) -> String {
self.msg.clone()
}
}
pub fn type_check(e: Expr) -> Result<Expr, TypeCheckError> {
match &e {
Expr::BinOp(Spanned {
source_span: _,
expr: bin,
}) => {
if bin.left.tpe() == bin.right.tpe() {
Ok(e)
} else {
Err(TypeCheckError::new(format!(
"Type check error: binary op operands types do not match: {0:?}",
bin
)))
}
}
_ => Ok(e),
}
}