internal: Record mismatches of pattern types.

This commit is contained in:
Dawer 2021-05-19 09:23:16 +05:00
parent 49a5d6a8d4
commit 472317c008
6 changed files with 93 additions and 11 deletions

View file

@ -42,7 +42,7 @@ impl<'a> InferenceContext<'a> {
let could_unify = self.unify(&ty, &expected.ty);
if !could_unify {
self.result.type_mismatches.insert(
tgt_expr,
tgt_expr.into(),
TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() },
);
}
@ -54,9 +54,10 @@ impl<'a> InferenceContext<'a> {
pub(super) fn infer_expr_coerce(&mut self, expr: ExprId, expected: &Expectation) -> Ty {
let ty = self.infer_expr_inner(expr, &expected);
let ty = if !self.coerce(&ty, &expected.coercion_target()) {
self.result
.type_mismatches
.insert(expr, TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() });
self.result.type_mismatches.insert(
expr.into(),
TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() },
);
// Return actual type when type mismatch.
// This is needed for diagnostic when return type mismatch.
ty