Implement binary operator overloading type inference

This commit is contained in:
Roland Ruckerbauer 2020-10-13 20:48:08 +02:00
parent 0fb069c5b0
commit 4e49b2f731
3 changed files with 120 additions and 5 deletions

View file

@ -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,
},