Replace throw 0 with real exceptions or assertions.

This commit is contained in:
2020-09-09 17:19:23 -07:00
parent 1f7a53ccf6
commit 92a9ec2021
6 changed files with 46 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
#include "definition.hpp"
#include <cassert>
#include "error.hpp"
#include "ast.hpp"
#include "instruction.hpp"
@@ -62,7 +63,10 @@ void definition_data::insert_constructors() const {
type_app* return_app = new type_app(std::move(this_type_ptr));
type_ptr return_type(return_app);
for(auto& var : vars) {
if(var_set.find(var) != var_set.end()) throw 0;
if(var_set.find(var) != var_set.end())
throw std::runtime_error(
std::string("type variable ") +
var + std::string(" used twice in data type definition."));
var_set.insert(var);
return_app->arguments.push_back(type_ptr(new type_var(var)));
}
@@ -121,8 +125,7 @@ void definition_group::typecheck(type_mgr& mgr, type_env_ptr& env) {
dependency_graph.add_function(def_defn.second->name);
for(auto& dependency : def_defn.second->nearby_variables) {
if(defs_defn.find(dependency) == defs_defn.end())
throw 0;
assert(defs_defn.find(dependency) != defs_defn.end());
dependency_graph.add_edge(def_defn.second->name, dependency);
}
}