feat(library/tactic/proof_state): apply substitutions when pretty printing state

This commit is contained in:
Leonardo de Moura 2014-10-14 17:37:20 -07:00
parent 58c9421bab
commit 90dba868e3
5 changed files with 27 additions and 4 deletions

View file

@ -11,11 +11,17 @@ Author: Leonardo de Moura
#include "kernel/for_each_fn.h" #include "kernel/for_each_fn.h"
#include "kernel/abstract.h" #include "kernel/abstract.h"
#include "kernel/type_checker.h" #include "kernel/type_checker.h"
#include "kernel/metavar.h"
#include "library/kernel_bindings.h" #include "library/kernel_bindings.h"
#include "library/tactic/goal.h" #include "library/tactic/goal.h"
namespace lean { namespace lean {
format goal::pp(formatter const & fmt) const { format goal::pp(formatter const & fmt) const {
return pp(fmt, substitution());
}
format goal::pp(formatter const & fmt, substitution const & s) const {
substitution tmp_subst(s);
options const & opts = fmt.get_options(); options const & opts = fmt.get_options();
unsigned indent = get_pp_indent(opts); unsigned indent = get_pp_indent(opts);
bool unicode = get_pp_unicode(opts); bool unicode = get_pp_unicode(opts);
@ -29,10 +35,11 @@ format goal::pp(formatter const & fmt) const {
for (auto it = tmp.begin(); it != end; ++it) { for (auto it = tmp.begin(); it != end; ++it) {
if (first) first = false; else r += compose(comma(), line()); if (first) first = false; else r += compose(comma(), line());
expr l = *it; expr l = *it;
r += fmt(l) + space() + colon() + nest(indent, line() + fmt(mlocal_type(l))); expr t = tmp_subst.instantiate(mlocal_type(l));
r += fmt(l) + space() + colon() + nest(indent, line() + fmt(t));
} }
r = group(r); r = group(r);
r += line() + turnstile + space() + nest(indent, fmt(conclusion)); r += line() + turnstile + space() + nest(indent, fmt(tmp_subst.instantiate(conclusion)));
return group(r); return group(r);
} }

View file

@ -72,6 +72,7 @@ public:
*/ */
list<expr> to_context() const; list<expr> to_context() const;
format pp(formatter const & fmt, substitution const & s) const;
format pp(formatter const & fmt) const; format pp(formatter const & fmt) const;
}; };

View file

@ -45,12 +45,13 @@ format proof_state::pp(formatter const & fmt) const {
unsigned indent = get_pp_indent(opts); unsigned indent = get_pp_indent(opts);
format r; format r;
bool first = true; bool first = true;
for (auto const & g : get_goals()) { for (auto const & g : get_goals()) {
if (first) first = false; else r += line(); if (first) first = false; else r += line();
if (show_goal_names) { if (show_goal_names) {
r += group(format(g.get_name()) + colon() + nest(indent, line() + g.pp(fmt))); r += group(format(g.get_name()) + colon() + nest(indent, line() + g.pp(fmt, m_subst)));
} else { } else {
r += g.pp(fmt); r += g.pp(fmt, m_subst);
} }
} }
if (first) r = format("no goals"); if (first) r = format("no goals");

9
tests/lean/goals1.lean Normal file
View file

@ -0,0 +1,9 @@
import tools.tactic
open tactic
set_option pp.notation false
theorem foo (A : Type) (a b c : A) (Hab : a = b) (Hbc : b = c) : a = c :=
begin
apply eq.trans,
apply Hbc
end

View file

@ -0,0 +1,5 @@
goals1.lean:9:0: error: unsolved placeholder, unsolved subgoals
A : Type, a : A, b : A, c : A, Hab : eq a b, Hbc : eq b c ⊢ eq a b
goals1.lean:9:0: error: failed to add declaration 'foo' to environment, value has metavariables
λ (A : Type) (a b c : A) (Hab : eq a b) (Hbc : eq b c),
?M_1