fix(frontends/lean/structure_cmd): check parent expression after elaboration as well
This commit is contained in:
parent
6781681ae5
commit
341cf71fb9
3 changed files with 30 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
15
tests/lean/structure_segfault.lean
Normal file
15
tests/lean/structure_segfault.lean
Normal 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
|
||||
5
tests/lean/structure_segfault.lean.expected.out
Normal file
5
tests/lean/structure_segfault.lean.expected.out
Normal 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
|
||||
Loading…
Add table
Reference in a new issue