fix(frontends/lean/parser): segfault when ending scope without opening, fixes #244

This commit is contained in:
Leonardo de Moura 2014-10-13 21:08:36 -07:00
parent 4a9e725ca7
commit d75a9c840c
4 changed files with 6 additions and 0 deletions

View file

@ -46,6 +46,7 @@ public:
std::tie(m_map, m_counter, m_entries) = head(m_scopes);
m_scopes = tail(m_scopes);
}
bool has_scopes() const { return !is_nil(m_scopes); }
bool empty() const { return m_map.empty(); }
struct mk_scope {
local_decls & m_d;

View file

@ -417,6 +417,9 @@ void parser::push_local_scope(bool save_options) {
}
void parser::pop_local_scope() {
if (!m_local_level_decls.has_scopes()) {
throw parser_error("invalid 'end', there is no open namespace/section/context", pos());
}
m_local_level_decls.pop();
m_local_decls.pop();
lean_assert(!is_nil(m_parser_scope_stack));

1
tests/lean/bad_end.lean Normal file
View file

@ -0,0 +1 @@
end foo

View file

@ -0,0 +1 @@
bad_end.lean:1:4: error: invalid 'end', there is no open namespace/section/context