aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
authorRoland Ruckerbauer <[email protected]>2020-10-13 19:48:08 +0100
committerRoland Ruckerbauer <[email protected]>2020-10-13 19:48:08 +0100
commit4e49b2f73144460cde5ada8140964d96166f41fd (patch)
treecb776951da53e297e59ba4bf372aa9285573cd82 /crates/hir_ty/src/infer/expr.rs
parent0fb069c5b02072239891ce564feaa7d1890c6d6f (diff)
Implement binary operator overloading type inference
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r--crates/hir_ty/src/infer/expr.rs15
1 files changed, 11 insertions, 4 deletions
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> {
531 _ => Expectation::none(), 531 _ => Expectation::none(),
532 }; 532 };
533 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); 533 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
534 // FIXME: find implementation of trait corresponding to operation
535 // symbol and resolve associated `Output` type
536 let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone()); 534 let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty.clone());
537 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation)); 535 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
538 536
539 // FIXME: similar as above, return ty is often associated trait type 537 let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone());
540 op::binary_op_return_ty(*op, lhs_ty, rhs_ty) 538
539 if ret == Ty::Unknown {
540 self.resolve_associated_type_with_params(
541 lhs_ty,
542 self.resolve_binary_op_output(op),
543 &[rhs_ty],
544 )
545 } else {
546 ret
547 }
541 } 548 }
542 _ => Ty::Unknown, 549 _ => Ty::Unknown,
543 }, 550 },