Prevent case compilation from crashing and burning.

This commit is contained in:
Danila Fedorin 2020-09-10 12:53:55 -07:00
parent 9fc0ff961d
commit 56f0dbd02f

View File

@ -204,10 +204,6 @@ type_ptr ast_case::typecheck(type_mgr& mgr, type_env_ptr& env) {
input_type = mgr.resolve(case_type, var);
type_app* app_type;
// if(!(app_type = dynamic_cast<type_app*>(input_type.get())) ||
// !dynamic_cast<type_data*>(app_type->constructor.get())) {
// throw type_error("attempting case analysis of non-data type", of->loc);
// }
return branch_type;
}
@ -407,17 +403,17 @@ void ast_case::compile(const env_ptr& env, std::vector<instruction_ptr>& into) c
of->compile(env, into);
into.push_back(instruction_ptr(new instruction_eval()));
if((data = dynamic_cast<type_data*>(app_type->constructor.get()))) {
if(app_type && (data = dynamic_cast<type_data*>(app_type->constructor.get()))) {
compile_case<case_strategy_data>(*this, env, data, into);
return;
} else if((internal = dynamic_cast<type_internal*>(app_type->constructor.get()))) {
} else if(app_type && (internal = dynamic_cast<type_internal*>(app_type->constructor.get()))) {
if(internal->name == "Bool") {
compile_case<case_strategy_bool>(*this, env, data, into);
return;
}
}
throw std::runtime_error("no known way to compile case expression");
throw type_error("attempting unsupported case analysis", of->loc);
}
void ast_let::print(int indent, std::ostream& to) const {