Naive typechecking of binary operators

master
Araozu 2024-05-06 09:53:18 -05:00
parent 4f7fa0f5e3
commit 7218898ce0
1 changed files with 20 additions and 2 deletions

View File

@ -26,12 +26,30 @@ impl Typed for Expression<'_> {
}))
}
};
Ok(datatype)
}
Expression::FunctionCall(_) => 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."
),
}));
}
}
}
}