fix(frontends/lean): universe variable is treated as parameter inside section, fixes #283

This commit is contained in:
Leonardo de Moura 2014-10-29 19:47:14 -07:00
parent d7ded15486
commit 6107da05db
5 changed files with 28 additions and 4 deletions

View file

@ -26,7 +26,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
static environment declare_universe(parser & p, environment env, name const & n, bool local) { static environment declare_universe(parser & p, environment env, name const & n, bool local) {
if (in_context(env) || local) { if (in_context(env) || local) {
p.add_local_level(n, mk_param_univ(n)); p.add_local_level(n, mk_param_univ(n), local);
} else { } else {
name const & ns = get_namespace(env); name const & ns = get_namespace(env);
name full_n = ns + n; name full_n = ns + n;
@ -399,9 +399,10 @@ environment definition_cmd_core(parser & p, bool is_theorem, bool is_opaque, boo
erase_local_binder_info(new_locals); erase_local_binder_info(new_locals);
value = Fun_as_is(new_locals, value, p); value = Fun_as_is(new_locals, value, p);
update_univ_parameters(ls_buffer, collect_univ_params(value, collect_univ_params(type)), p); update_univ_parameters(ls_buffer, collect_univ_params(value, collect_univ_params(type)), p);
remove_local_vars(p, locals);
ls = to_list(ls_buffer.begin(), ls_buffer.end()); ls = to_list(ls_buffer.begin(), ls_buffer.end());
levels local_ls = collect_local_nonvar_levels(p, ls); levels local_ls = collect_local_nonvar_levels(p, ls);
remove_local_vars(p, locals); local_ls = remove_local_vars(p, local_ls);
if (!locals.empty()) { if (!locals.empty()) {
expr ref = mk_local_ref(real_n, local_ls, locals); expr ref = mk_local_ref(real_n, local_ls, locals);
p.add_local_expr(n, ref); p.add_local_expr(n, ref);

View file

@ -98,6 +98,12 @@ void remove_local_vars(parser const & p, buffer<expr> & locals) {
locals.shrink(j); locals.shrink(j);
} }
levels remove_local_vars(parser const & p, levels const & ls) {
return filter(ls, [&](level const & l) {
return !is_param(l) || !p.is_local_level_variable(param_id(l));
});
}
list<expr> locals_to_context(expr const & e, parser const & p) { list<expr> locals_to_context(expr const & e, parser const & p) {
expr_struct_set ls; expr_struct_set ls;
collect_locals(e, ls); collect_locals(e, ls);

View file

@ -32,6 +32,8 @@ void collect_locals(expr const & type, expr const & value, parser const & p, buf
void sort_locals(expr_struct_set const & locals, parser const & p, buffer<expr> & ps); void sort_locals(expr_struct_set const & locals, parser const & p, buffer<expr> & ps);
/** \brief Remove from \c ps local constants that are tagged as variables. */ /** \brief Remove from \c ps local constants that are tagged as variables. */
void remove_local_vars(parser const & p, buffer<expr> & ps); void remove_local_vars(parser const & p, buffer<expr> & ps);
/** \brief Remove from \c ls any universe level that is tagged as variable in \c p */
levels remove_local_vars(parser const & p, levels const & ls);
list<expr> locals_to_context(expr const & e, parser const & p); list<expr> locals_to_context(expr const & e, parser const & p);
/** \brief Create the term <tt>(as_atomic (@n.{ls} @params[0] ... @params[num_params-1]))</tt> /** \brief Create the term <tt>(as_atomic (@n.{ls} @params[0] ... @params[num_params-1]))</tt>
When we declare \c n inside of a context, the parameters and universes are fixed. When we declare \c n inside of a context, the parameters and universes are fixed.

View file

@ -0,0 +1,15 @@
import logic.eq
section
universe variable u
variables {A B : Type.{u}}
theorem foo (H : A = B) : A = B := H
theorem bar {C D : Type} (H : C = D) : C = D :=
foo H
end
universe variable u
variables {A B : Type.{u}}
theorem foo2 (H : A = B) : A = B := H
theorem bar2 {C D : Type} (H : C = D) : C = D :=
foo2 H

View file

@ -1,5 +1,5 @@
id1 : Π (A : Type.{u}), A → A id1 : Π (A : Type.{u}), A → A
id2.{l_2} : Π (B : Type.{l_2}), B → B id2.{l_2} : Π (B : Type.{l_2}), B → B
id3.{k} : Π (C : Type.{k}), C → C id3.{l_2} : Π (C : Type.{l_2}), C → C
foo.{l} : Π (A₁ A₂ : Type.{l}), A₁ → A₂ → Prop foo.{l_2} : Π (A₁ A₂ : Type.{l_2}), A₁ → A₂ → Prop
Type.{m} : Type.{succ m} Type.{m} : Type.{succ m}