fix: do not assume the constructor name prefix is the inductive type name

This commit is contained in:
Leonardo de Moura 2020-07-23 14:36:54 -07:00
parent 07cb21c609
commit ea5eed7964
3 changed files with 13 additions and 1 deletions

View file

@ -685,7 +685,7 @@ static bool is_structure_instance(environment const & env, expr const & e, bool
if (!is_constant(fn)) return false;
name const & mk_name = const_name(fn);
if (!is_constructor(env, mk_name)) return false;
name const & S = mk_name.get_prefix();
name S = get_constructor_inductive_type(env, mk_name);
if (!is_structure(env, S)) return false;
/* If implicit arguments is true, and the structure has parameters, we should not
pretty print using { ... }, because we will not be able to see the parameters. */

View file

@ -318,6 +318,13 @@ unsigned get_constructor_idx(environment const & env, name const & n) {
lean_unreachable();
}
name get_constructor_inductive_type(environment const & env, name const & ctor_name) {
constant_info info = env.get(ctor_name);
lean_assert(info.is_constructor());
constructor_val val = info.to_constructor_val();
return val.get_induct();
}
expr instantiate_lparam(expr const & e, name const & p, level const & l) {
return instantiate_lparams(e, names(p), levels(l));
}

View file

@ -124,6 +124,11 @@ unsigned get_num_constructors(environment const & env, name const & n);
\pre inductive::is_intro_rule(env, n) */
unsigned get_constructor_idx(environment const & env, name const & n);
/** \brief Given a constructor name, return the associated inductive type name.
\pre inductive::is_intro_rule(env, ctor_name) */
name get_constructor_inductive_type(environment const & env, name const & ctor_name);
/** \brief Given an expression \c e, return the number of arguments expected arguments.
\remark This function counts the number of nested Pi's in \c e. Weak-head-normal-forms are computed for the type of \c e.