From bb7347c97b2a038b9b54e6d497c1c664e932e1ea Mon Sep 17 00:00:00 2001 From: sofia Date: Mon, 28 Jul 2025 14:30:57 +0300 Subject: [PATCH] Possibly fix binop type inferrence --- reid/src/mir/typecheck/typecheck.rs | 3 +++ reid/src/mir/typecheck/typerefs.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/reid/src/mir/typecheck/typecheck.rs b/reid/src/mir/typecheck/typecheck.rs index dca27bb..e6ee204 100644 --- a/reid/src/mir/typecheck/typecheck.rs +++ b/reid/src/mir/typecheck/typecheck.rs @@ -415,6 +415,7 @@ impl Expression { // First find unfiltered parameters to binop let lhs_res = lhs.typecheck(state, &typerefs, HintKind::None); let rhs_res = rhs.typecheck(state, &typerefs, HintKind::None); + dbg!(&lhs_res, &rhs_res, &ret_ty); let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1); let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1); @@ -431,6 +432,8 @@ impl Expression { params: (lhs_type.clone(), rhs_type.clone()), operator: *op, }); + + dbg!(&binops); // dbg!(&lhs_type, &rhs_type, &binops, &ret_ty, &expected_return_ty); if let Some(binop) = binops .iter() diff --git a/reid/src/mir/typecheck/typerefs.rs b/reid/src/mir/typecheck/typerefs.rs index e4f87e8..c07f3f0 100644 --- a/reid/src/mir/typecheck/typerefs.rs +++ b/reid/src/mir/typecheck/typerefs.rs @@ -356,6 +356,12 @@ impl<'outer> ScopeTypeRefs<'outer> { rhs_ref.narrow(&self.from_type(&rhs_widened).unwrap()); } } + (TypeRefKind::BinOp(_, lhs1, rhs1), TypeRefKind::BinOp(_, lhs2, rhs2)) => { + let mut lhs_ref = self.from_type(&lhs1).unwrap(); + let mut rhs_ref = self.from_type(&rhs1).unwrap(); + lhs_ref.narrow(&self.from_type(&lhs2).unwrap()); + rhs_ref.narrow(&self.from_type(&rhs2).unwrap()); + } _ => {} }