Fix coercion in match with expected type

Plus add infrastructure to test type mismatches without expect.
This commit is contained in:
Florian Diebold 2021-06-03 23:12:35 +02:00
parent 124123a53b
commit 20487a1b4a
6 changed files with 183 additions and 54 deletions

View file

@ -337,10 +337,15 @@ impl<'a> InferenceContext<'a> {
Expr::Match { expr, arms } => {
let input_ty = self.infer_expr(*expr, &Expectation::none());
let expected = expected.adjust_for_branches(&mut self.table);
let mut result_ty = if arms.is_empty() {
TyKind::Never.intern(&Interner)
} else {
self.table.new_type_var()
match &expected {
Expectation::HasType(ty) => ty.clone(),
_ => self.table.new_type_var(),
}
};
let matchee_diverges = self.diverges;