mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Fix coercion in match with expected type
Plus add infrastructure to test type mismatches without expect.
This commit is contained in:
parent
124123a53b
commit
20487a1b4a
6 changed files with 183 additions and 54 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue