fix(frontends/lean/structure_cmd): check parent expression after elaboration as well

This commit is contained in:
Gabriel Ebner 2017-09-14 09:36:40 +02:00
parent 6781681ae5
commit 341cf71fb9
3 changed files with 30 additions and 0 deletions

View file

@ -350,6 +350,15 @@ struct structure_cmd_fn {
throw parser_error(sstream() << "invalid 'structure' extends, '" << S << "' is not a structure", pos);
}
void check_parent(expr const & parent) {
expr const & fn = get_app_fn(parent);
if (!is_constant(fn))
throw elaborator_exception(parent, "invalid 'structure', expression must be a 'parent' structure");
name const & S = const_name(fn);
if (!is_structure_like(m_env, S))
throw elaborator_exception(parent, sstream() << "invalid 'structure' extends, '" << S << "' is not a structure");
}
/** \brief Return the universe parameters, number of parameters and introduction rule for the given parent structure */
std::tuple<level_param_names, unsigned, inductive::intro_rule> get_parent_info(name const & parent) {
return get_structure_info(m_env, parent);
@ -589,6 +598,7 @@ struct structure_cmd_fn {
for (unsigned i = 0; i < m_parents.size(); i++) {
expr const & parent = m_parents[i];
check_parent(parent);
rename_vector const & renames = m_renames[i];
m_field_maps.push_back(field_map());
field_map & fmap = m_field_maps.back();

View file

@ -0,0 +1,15 @@
universes u
namespace hide
structure group (α : Type u) : Type u
structure T (α : extends group α := ()
structure ring (α : Type u) : Type u
class T (α : Type*) extends ring x α
class S (α : Type*) extends ((λ x, group x) α)
end hide

View file

@ -0,0 +1,5 @@
structure_segfault.lean:7:17: error: invalid expression
structure_segfault.lean:7:25: error: invalid 'structure', expression must be a 'parent' structure
structure_segfault.lean:11:33: error: unknown identifier 'x'
structure_segfault.lean:11:28: error: invalid 'structure', expression must be a 'parent' structure
structure_segfault.lean:13:28: error: invalid 'structure', expression must be a 'parent' structure