feat(library/tactic/rewrite_tactic): display type error message when

rewrite tactic fails
This commit is contained in:
Leonardo de Moura 2015-05-05 19:21:27 -07:00
parent 9bb8c5c98a
commit a4efefb6ff
2 changed files with 33 additions and 10 deletions

View file

@ -1427,28 +1427,43 @@ class rewrite_fn {
}
}
void process_failure(expr const & elem, bool type_error) {
void process_failure(expr const & elem, bool type_error, kernel_exception * ex = nullptr) {
std::shared_ptr<kernel_exception> saved_ex;
if (ex)
saved_ex.reset(static_cast<kernel_exception*>(ex->clone()));
if (m_ps.report_failure()) {
proof_state curr_ps(m_ps, cons(m_g, tail(m_ps.get_goals())), m_subst, m_ngen);
if (!m_use_trace || !m_trace_initialized) {
throw tactic_exception("rewrite step failed", some_expr(elem), curr_ps,
[=](formatter const &) {
if (type_error)
return format("invalid 'rewrite' tactic, "
[=](formatter const & fmt) {
format r;
if (type_error) {
r = format("invalid 'rewrite' tactic, "
"rewrite step produced type incorrect term");
else
return format("invalid 'rewrite' tactic, rewrite step failed");
if (saved_ex) {
r += saved_ex->pp(fmt);
r += line();
}
} else {
r = format("invalid 'rewrite' tactic, rewrite step failed");
}
return r;
});
} else {
trace saved_trace = m_trace;
throw tactic_exception("rewrite step failed", some_expr(elem), curr_ps,
[=](formatter const & fmt) {
format r;
if (type_error)
if (type_error) {
r += format("invalid 'rewrite' tactic, "
"step produced type incorrect term, details: ");
else
if (saved_ex) {
r += saved_ex->pp(fmt);
r += line();
}
} else {
r += format("invalid 'rewrite' tactic, ");
}
r += saved_trace.pp(fmt);
return r;
});
@ -1481,7 +1496,7 @@ public:
return proof_state_seq();
}
} catch (kernel_exception & ex) {
process_failure(elem, true);
process_failure(elem, true, &ex);
return proof_state_seq();
}
}

View file

@ -1,4 +1,12 @@
550.lean:44:72: error:invalid 'rewrite' tactic, step produced type incorrect term, details: rewrite step failed using pattern
550.lean:44:72: error:invalid 'rewrite' tactic, step produced type incorrect term, details: type mismatch at application
eq.rec (eq.rec (eq.refl function.id) (eq.symm linv))
term
eq.rec (eq.refl function.id) (eq.symm linv)
has type
x = function.id
but is expected to have type
finv ∘ func = function.id
rewrite step failed using pattern
finv ∘ func
proof state:
A : Type,