diff --git a/reid/src/mir/implement.rs b/reid/src/mir/implement.rs index c2501db..418a7a6 100644 --- a/reid/src/mir/implement.rs +++ b/reid/src/mir/implement.rs @@ -107,6 +107,16 @@ impl TypeKind { } } + pub fn binop_hint(&self, op: &BinaryOperator) -> Option { + 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, diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index eb89319..ba606ff 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -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); diff --git a/reid_src/float.reid b/reid_src/float.reid index 717f585..903131c 100644 --- a/reid_src/float.reid +++ b/reid_src/float.reid @@ -5,5 +5,5 @@ pub fn OneHalf(var1: f32) -> f32 { } pub fn main() -> bool { - return 7.5 > 5.5; + return (7.5 > 5.5); }