From 138267b53a79b95932a728d8b51cf908d6c54e80 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Wed, 2 Jul 2014 18:58:32 -0700 Subject: [PATCH] feat(frontends/lean/elaborator) add trick for improving error messages when mixing tactics, elaboration and exact tactic Signed-off-by: Leonardo de Moura --- src/frontends/lean/elaborator.cpp | 15 +++++++++++++++ src/library/tactic/expr_to_tactic.cpp | 4 +++- src/library/tactic/expr_to_tactic.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/frontends/lean/elaborator.cpp b/src/frontends/lean/elaborator.cpp index eafc4faa7..fdce77793 100644 --- a/src/frontends/lean/elaborator.cpp +++ b/src/frontends/lean/elaborator.cpp @@ -640,10 +640,25 @@ public: } } + // For each occurrence of \c exact_tac in \c pre_tac, display its unassigned metavariables. + // This is a trick to improve the quality of the error messages. + void check_exact_tacs(expr const & pre_tac, substitution const & s) { + for_each(pre_tac, [&](expr const & e, unsigned) { + expr const & f = get_app_fn(e); + if (is_constant(f) && const_name(f) == get_exact_tac_name()) { + display_unassigned_mvars(e, s); + return false; + } else { + return true; + } + }); + } + optional get_pre_tactic_for(substitution & subst, expr const & mvar, name_set & visited) { if (auto it = m_tactic_hints.find(mlocal_name(mvar))) { expr pre_tac = subst.instantiate(*it); pre_tac = solve_unassigned_mvars(subst, pre_tac, visited); + check_exact_tacs(pre_tac, subst); return some_expr(pre_tac); } else { // TODO(Leo): m_env tactic hints diff --git a/src/library/tactic/expr_to_tactic.cpp b/src/library/tactic/expr_to_tactic.cpp index fce79abd1..1ea3c841c 100644 --- a/src/library/tactic/expr_to_tactic.cpp +++ b/src/library/tactic/expr_to_tactic.cpp @@ -81,6 +81,8 @@ register_unary_tac::register_unary_tac(name const & n, std::function f); }; +name const & get_exact_tac_name(); + tactic expr_to_tactic(environment const & env, expr const & e, pos_info_provider const *p); expr mk_by(expr const & e); bool is_by(expr const & e);