Also mark InferenceResult::has_errors flag when there are error types

This commit is contained in:
Lukas Wirth 2024-07-06 20:41:46 +02:00
parent bb9678ea3b
commit e0105c473e
2 changed files with 6 additions and 3 deletions

View file

@ -701,18 +701,23 @@ impl<'a> InferenceContext<'a> {
table.propagate_diverging_flag(); table.propagate_diverging_flag();
for ty in type_of_expr.values_mut() { for ty in type_of_expr.values_mut() {
*ty = table.resolve_completely(ty.clone()); *ty = table.resolve_completely(ty.clone());
*has_errors = *has_errors || ty.contains_unknown();
} }
for ty in type_of_pat.values_mut() { for ty in type_of_pat.values_mut() {
*ty = table.resolve_completely(ty.clone()); *ty = table.resolve_completely(ty.clone());
*has_errors = *has_errors || ty.contains_unknown();
} }
for ty in type_of_binding.values_mut() { for ty in type_of_binding.values_mut() {
*ty = table.resolve_completely(ty.clone()); *ty = table.resolve_completely(ty.clone());
*has_errors = *has_errors || ty.contains_unknown();
} }
for ty in type_of_rpit.values_mut() { for ty in type_of_rpit.values_mut() {
*ty = table.resolve_completely(ty.clone()); *ty = table.resolve_completely(ty.clone());
*has_errors = *has_errors || ty.contains_unknown();
} }
for ty in type_of_for_iterator.values_mut() { for ty in type_of_for_iterator.values_mut() {
*ty = table.resolve_completely(ty.clone()); *ty = table.resolve_completely(ty.clone());
*has_errors = *has_errors || ty.contains_unknown();
} }
*has_errors = !type_mismatches.is_empty(); *has_errors = !type_mismatches.is_empty();

View file

@ -2160,9 +2160,7 @@ pub fn lower_to_mir(
root_expr: ExprId, root_expr: ExprId,
) -> Result<MirBody> { ) -> Result<MirBody> {
if infer.has_errors { if infer.has_errors {
return Err(MirLowerError::TypeMismatch( return Err(MirLowerError::TypeMismatch(None));
infer.type_mismatches().next().map(|(_, it)| it.clone()),
));
} }
let mut ctx = MirLowerCtx::new(db, owner, body, infer); let mut ctx = MirLowerCtx::new(db, owner, body, infer);
// 0 is return local // 0 is return local