Fix crash when trying to format an object created by a different frontend.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-08-17 11:04:22 -07:00
parent b633c866e6
commit 0f3af23778
2 changed files with 26 additions and 1 deletions

View file

@ -689,7 +689,13 @@ public:
case object_kind::Postulate: return pp_postulate(obj);
case object_kind::Definition: return pp_definition(obj);
case object_kind::Neutral:
return pp_notation_decl(obj);
if (dynamic_cast<notation_declaration const *>(obj.cell())) {
// If the object is not notation, then the object was
// created in different frontend, and we ignore it.
return pp_notation_decl(obj);
} else {
return format("Unknown neutral object");
}
}
lean_unreachable();
return format();

View file

@ -90,11 +90,30 @@ static void tst5() {
}
}
class alien_cell : public neutral_object_cell {
unsigned m_data[128];
public:
alien_cell() {}
unsigned & get_data(unsigned i) { return m_data[i]; }
virtual char const * keyword() const { return "alien"; }
};
static void tst6() {
std::cout << "=================\n";
frontend f;
environment env;
env.add_neutral_object(new alien_cell());
std::shared_ptr<formatter> fmt_ptr = mk_pp_formatter(f);
formatter & fmt = *fmt_ptr;
std::cout << fmt(env) << "\n";
}
int main() {
tst1();
tst2();
tst3();
tst4();
tst5();
tst6();
return has_violations() ? 1 : 0;
}