diff --git a/src/frontends/lean/decl_cmds.cpp b/src/frontends/lean/decl_cmds.cpp index 7b91b5586..fc886a4dd 100644 --- a/src/frontends/lean/decl_cmds.cpp +++ b/src/frontends/lean/decl_cmds.cpp @@ -362,10 +362,8 @@ environment definition_cmd_core(parser & p, bool is_theorem, bool is_opaque, boo ls = to_list(ls_buffer.begin(), ls_buffer.end()); levels section_ls = collect_section_nonvar_levels(p, ls); remove_section_variables(p, section_ps); - for (expr & param : section_ps) - param = mk_explicit(param); if (!section_ps.empty()) { - expr ref = mk_implicit(mk_app(mk_explicit(mk_constant(real_n, section_ls)), section_ps)); + expr ref = mk_section_local_ref(real_n, section_ls, section_ps.size(), section_ps.data()); p.add_local_expr(n, ref); } else if (section_ls) { expr ref = mk_constant(real_n, section_ls); diff --git a/src/frontends/lean/inductive_cmd.cpp b/src/frontends/lean/inductive_cmd.cpp index 400831a04..ac82376eb 100644 --- a/src/frontends/lean/inductive_cmd.cpp +++ b/src/frontends/lean/inductive_cmd.cpp @@ -594,9 +594,7 @@ struct inductive_cmd_fn { else id = name(full_id.get_string()); if (in_section_or_context(env)) { - expr r = mk_explicit(mk_constant(full_id, section_levels)); - r = mk_app(r, section_params); - r = mk_implicit(r); + expr r = mk_section_local_ref(full_id, section_levels, section_params.size(), section_params.data()); m_p.add_local_expr(id, r); } if (full_id != id) diff --git a/src/frontends/lean/util.cpp b/src/frontends/lean/util.cpp index 155ef4e95..53a2ccbf5 100644 --- a/src/frontends/lean/util.cpp +++ b/src/frontends/lean/util.cpp @@ -107,6 +107,13 @@ list locals_to_context(expr const & e, parser const & p) { return to_list(locals.begin(), locals.end()); } +expr mk_section_local_ref(name const & n, levels const & sec_ls, unsigned num_sec_params, expr const * sec_params) { + buffer params; + for (unsigned i = 0; i < num_sec_params; i++) + params.push_back(mk_explicit(sec_params[i])); + return mk_implicit(mk_app(mk_explicit(mk_constant(n, sec_ls)), params)); +} + expr Fun(buffer const & locals, expr const & e, parser & p) { bool use_cache = false; return p.rec_save_pos(Fun(locals, e, use_cache), p.pos_of(e)); diff --git a/src/frontends/lean/util.h b/src/frontends/lean/util.h index 77a7294c3..096c9dfdf 100644 --- a/src/frontends/lean/util.h +++ b/src/frontends/lean/util.h @@ -31,6 +31,12 @@ void sort_section_params(expr_struct_set const & locals, parser const & p, buffe /** \brief Remove from \c ps local constants that are tagged as section variables. */ void remove_section_variables(parser const & p, buffer & ps); list locals_to_context(expr const & e, parser const & p); +/** \brief Create the term (@^-1 (@n.{sec_ls} @sec_params[0] ... @sec_params[num_sec_params-1])) + When we declare \c n inside of a section, the section parameters and universes are fixes. + That is, when the user writes \c n inside the section she is really getting the term returned by this function. +*/ +expr mk_section_local_ref(name const & n, levels const & sec_ls, unsigned num_sec_params, expr const * sec_params); + /** \brief Fun(locals, e), but also propagate \c e position to result */ expr Fun(buffer const & locals, expr const & e, parser & p); /** \brief Pi(locals, e), but also propagate \c e position to result */