From a680064b0f54bbe86e8b340f6a11adf194abbf70 Mon Sep 17 00:00:00 2001 From: sofia Date: Mon, 28 Jul 2025 14:22:27 +0300 Subject: [PATCH] Improve binary operation inference, still not great --- reid/src/mir/typecheck/typeinference.rs | 4 ++-- reid/src/mir/typecheck/typerefs.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/reid/src/mir/typecheck/typeinference.rs b/reid/src/mir/typecheck/typeinference.rs index 8adb0c6..795b2bf 100644 --- a/reid/src/mir/typecheck/typeinference.rs +++ b/reid/src/mir/typecheck/typeinference.rs @@ -285,8 +285,8 @@ impl Block { let rhs_ref = state.ok(rhs_infer, rhs.1); // Try to narrow the lhs with rhs - if let (Some(mut lhs_ref), Some(rhs_ref)) = (lhs_ref, rhs_ref) { - lhs_ref.narrow(&rhs_ref); + if let (Some(mut lhs_ref), Some(mut rhs_ref)) = (lhs_ref, rhs_ref) { + rhs_ref.narrow(&lhs_ref); } } StmtKind::Import(_) => panic!(), diff --git a/reid/src/mir/typecheck/typerefs.rs b/reid/src/mir/typecheck/typerefs.rs index bdca213..e4f87e8 100644 --- a/reid/src/mir/typecheck/typerefs.rs +++ b/reid/src/mir/typecheck/typerefs.rs @@ -366,7 +366,11 @@ impl<'outer> ScopeTypeRefs<'outer> { *idx.borrow_mut() = *hint1.0.borrow(); } } - (TypeRefKind::Direct(_), TypeRefKind::BinOp(..)) => {} + (TypeRefKind::Direct(_), TypeRefKind::BinOp(..)) => { + if *idx == hint1.0 && idx != &hint2.0 { + *idx.borrow_mut() = *hint2.0.borrow(); + } + } (TypeRefKind::BinOp(..), TypeRefKind::Direct(..)) => { // TODO may not be good ? // if *idx == hint2.0 && idx != &hint1.0 {