Add binop_hint

This commit is contained in:
Sofia 2025-07-22 23:14:38 +03:00
parent c4f78471cd
commit 8954d1a6d0
3 changed files with 16 additions and 2 deletions

View File

@ -107,6 +107,16 @@ impl TypeKind {
}
}
pub fn binop_hint(&self, op: &BinaryOperator) -> Option<TypeKind> {
match op {
BinaryOperator::Add | BinaryOperator::Minus | BinaryOperator::Mult => {
Some(self.clone())
}
BinaryOperator::And => None,
BinaryOperator::Cmp(_) => None,
}
}
pub fn signed(&self) -> bool {
match self {
TypeKind::Bool => false,

View File

@ -408,7 +408,11 @@ impl Expression {
ExprKind::BinOp(op, lhs, rhs) => {
// TODO make sure lhs and rhs can actually do this binary
// operation once relevant
let lhs_res = lhs.typecheck(state, &typerefs, hint_t);
let lhs_res = lhs.typecheck(
state,
&typerefs,
hint_t.and_then(|t| t.binop_hint(op)).as_ref(),
);
let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1);
let rhs_res = rhs.typecheck(state, &typerefs, Some(&lhs_type));
let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1);

View File

@ -5,5 +5,5 @@ pub fn OneHalf(var1: f32) -> f32 {
}
pub fn main() -> bool {
return 7.5 > 5.5;
return (7.5 > 5.5);
}