fix inference in nested closure

This commit is contained in:
hkalbasi 2023-04-11 17:02:00 +03:30
parent fa3db447d7
commit 85f9235de8
2 changed files with 18 additions and 1 deletions

View File

@ -462,7 +462,7 @@ fn walk_expr_without_adjust(&mut self, tgt_expr: ExprId) {
}
fn expr_ty(&mut self, expr: ExprId) -> Ty {
self.infer_expr_no_expect(expr)
self.result[expr].clone()
}
fn is_upvar(&self, place: &HirPlace) -> bool {

View File

@ -1067,6 +1067,23 @@ fn parse_arule() {
)
}
#[test]
fn nested_closure() {
check_types(
r#"
//- minicore: fn, option
fn map<T, U>(o: Option<T>, f: impl FnOnce(T) -> U) -> Option<U> { loop {} }
fn test() {
let o = Some(Some(2));
map(o, |s| map(s, |x| x));
// ^ i32
}
"#,
);
}
#[test]
fn call_expected_type_closure() {
check_types(