Replace throw 0 with real exceptions or assertions.
This commit is contained in:
@@ -1,15 +1,26 @@
|
||||
#include "parsed_type.hpp"
|
||||
#include <sstream>
|
||||
#include "type.hpp"
|
||||
#include "type_env.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
type_ptr parsed_type_app::to_type(
|
||||
const std::set<std::string>& vars,
|
||||
const type_env& e) const {
|
||||
auto parent_type = e.lookup_type(name);
|
||||
if(parent_type == nullptr) throw 0;
|
||||
if(parent_type == nullptr)
|
||||
throw type_error(std::string("no such type or type constructor ") + name);
|
||||
type_base* base_type;
|
||||
if(!(base_type = dynamic_cast<type_base*>(parent_type.get()))) throw 0;
|
||||
if(base_type->arity != arguments.size()) throw 0;
|
||||
if(!(base_type = dynamic_cast<type_base*>(parent_type.get())))
|
||||
throw type_error(std::string("invalid type ") + name);
|
||||
if(base_type->arity != arguments.size()) {
|
||||
std::ostringstream error_stream;
|
||||
error_stream << "invalid application of type ";
|
||||
error_stream << name;
|
||||
error_stream << "(" << base_type->arity << " arguments expected, ";
|
||||
error_stream << "but " << arguments.size() << " were provided)";
|
||||
throw type_error(error_stream.str());
|
||||
}
|
||||
|
||||
type_app* new_app = new type_app(std::move(parent_type));
|
||||
type_ptr to_return(new_app);
|
||||
@@ -22,7 +33,8 @@ type_ptr parsed_type_app::to_type(
|
||||
type_ptr parsed_type_var::to_type(
|
||||
const std::set<std::string>& vars,
|
||||
const type_env& e) const {
|
||||
if(vars.find(var) == vars.end()) throw 0;
|
||||
if(vars.find(var) == vars.end())
|
||||
throw type_error(std::string("the type variable ") + var + std::string(" was not explicitly declared."));
|
||||
return type_ptr(new type_var(var));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user