chore(frontends/lean/elaborator): cleanup ensure fun

This commit is contained in:
Leonardo de Moura 2015-05-20 15:10:45 -07:00
parent af3f0088f4
commit 608984cd4c

View file

@ -385,18 +385,13 @@ pair<expr, expr> elaborator::ensure_fun(expr f, constraint_seq & cs) {
expr f_type = infer_type(f, cs);
if (!is_pi(f_type))
f_type = whnf(f_type, cs);
if (!is_pi(f_type) && has_metavar(f_type)) {
constraint_seq saved_cs = cs;
expr new_f_type = whnf(f_type, cs);
if (!is_pi(new_f_type) && m_tc->is_stuck(new_f_type)) {
cs = saved_cs;
// let type checker add constraint
f_type = m_tc->ensure_pi(f_type, f, cs);
if (is_pi(f_type)) {
erase_coercion_info(f);
} else {
if (m_tc->is_stuck(f_type)) {
f_type = m_tc->ensure_pi(f_type, f, cs);
erase_coercion_info(f);
} else {
f_type = new_f_type;
}
}
if (!is_pi(f_type)) {
// try coercion to function-class
list<expr> coes = get_coercions_to_fun(env(), f_type);
if (is_nil(coes)) {
@ -435,8 +430,7 @@ pair<expr, expr> elaborator::ensure_fun(expr f, constraint_seq & cs) {
f_type = m_tc->ensure_pi(f_type, f, cs);
lean_assert(is_pi(f_type));
}
} else {
erase_coercion_info(f);
}
}
lean_assert(is_pi(f_type));
return mk_pair(f, f_type);