infer: update resolver when descending into block
This commit is contained in:
parent
82a1b91f20
commit
e837df8479
@ -137,24 +137,28 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
|
||||
|
||||
self.coerce_merge_branch(&then_ty, &else_ty)
|
||||
}
|
||||
Expr::Block { statements, tail, label, id: _ } => match label {
|
||||
Some(_) => {
|
||||
let break_ty = self.table.new_type_var();
|
||||
self.breakables.push(BreakableContext {
|
||||
may_break: false,
|
||||
break_ty: break_ty.clone(),
|
||||
label: label.map(|label| self.body[label].name.clone()),
|
||||
});
|
||||
let ty = self.infer_block(statements, *tail, &Expectation::has_type(break_ty));
|
||||
let ctxt = self.breakables.pop().expect("breakable stack broken");
|
||||
if ctxt.may_break {
|
||||
ctxt.break_ty
|
||||
} else {
|
||||
ty
|
||||
Expr::Block { statements, tail, label, id: _ } => {
|
||||
self.resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
|
||||
match label {
|
||||
Some(_) => {
|
||||
let break_ty = self.table.new_type_var();
|
||||
self.breakables.push(BreakableContext {
|
||||
may_break: false,
|
||||
break_ty: break_ty.clone(),
|
||||
label: label.map(|label| self.body[label].name.clone()),
|
||||
});
|
||||
let ty =
|
||||
self.infer_block(statements, *tail, &Expectation::has_type(break_ty));
|
||||
let ctxt = self.breakables.pop().expect("breakable stack broken");
|
||||
if ctxt.may_break {
|
||||
ctxt.break_ty
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
}
|
||||
None => self.infer_block(statements, *tail, expected),
|
||||
}
|
||||
None => self.infer_block(statements, *tail, expected),
|
||||
},
|
||||
}
|
||||
Expr::Unsafe { body } | Expr::Const { body } => self.infer_expr(*body, expected),
|
||||
Expr::TryBlock { body } => {
|
||||
let _inner = self.infer_expr(*body, expected);
|
||||
|
@ -2415,3 +2415,22 @@ fn foo<const FOO: usize>() {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_inner_type() {
|
||||
check_infer(r#"
|
||||
fn foo() {
|
||||
struct S { field: u32 }
|
||||
let s = S { field: 0 };
|
||||
let f = s.field;
|
||||
}
|
||||
"#, expect![[r#"
|
||||
9..89 '{ ...eld; }': ()
|
||||
47..48 's': S
|
||||
51..65 'S { field: 0 }': S
|
||||
62..63 '0': u32
|
||||
75..76 'f': u32
|
||||
79..80 's': S
|
||||
79..86 's.field': u32
|
||||
"#]]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user