From 4e49b2f73144460cde5ada8140964d96166f41fd Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Tue, 13 Oct 2020 20:48:08 +0200 Subject: Implement binary operator overloading type inference --- crates/hir_ty/src/infer/expr.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/hir_ty/src/infer/expr.rs') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 0a141b9cb..8cc0d56d3 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -531,13 +531,20 @@ impl<'a> InferenceContext<'a> { _ => Expectation::none(), }; let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); - // FIXME: find implementation of trait corresponding to operation - // symbol and resolve associated `Output` type let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone()); let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation)); - // FIXME: similar as above, return ty is often associated trait type - op::binary_op_return_ty(*op, lhs_ty, rhs_ty) + let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone()); + + if ret == Ty::Unknown { + self.resolve_associated_type_with_params( + lhs_ty, + self.resolve_binary_op_output(op), + &[rhs_ty], + ) + } else { + ret + } } _ => Ty::Unknown, }, -- cgit v1.2.3