Print locations in non-unification type errors.

This commit is contained in:
Danila Fedorin 2020-09-09 15:15:25 -07:00
parent d0fac50cfd
commit eade42be49

View File

@ -97,7 +97,7 @@ type_ptr ast_binop::typecheck(type_mgr& mgr, type_env_ptr& env) {
type_ptr ltype = left->typecheck(mgr, env);
type_ptr rtype = right->typecheck(mgr, env);
type_ptr ftype = env->lookup(op_name(op))->instantiate(mgr);
if(!ftype) throw type_error(std::string("unknown binary operator ") + op_name(op));
if(!ftype) throw type_error(std::string("unknown binary operator ") + op_name(op), loc);
type_ptr return_type = mgr.new_type();
type_ptr arrow_one = type_ptr(new type_arr(rtype, return_type));
@ -197,7 +197,7 @@ type_ptr ast_case::typecheck(type_mgr& mgr, type_env_ptr& env) {
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");
throw type_error("attempting case analysis of non-data type", of->loc);
}
return branch_type;
@ -251,7 +251,7 @@ void ast_case::compile(const env_ptr& env, std::vector<instruction_ptr>& into) c
int new_tag = type->constructors[cpat->constr].tag;
if(jump_instruction->tag_mappings.find(new_tag) !=
jump_instruction->tag_mappings.end())
throw type_error("technically not a type error: duplicate pattern");
throw type_error("technically not a type error: duplicate pattern", cpat->loc);
jump_instruction->tag_mappings[new_tag] =
jump_instruction->branches.size();
@ -262,7 +262,7 @@ void ast_case::compile(const env_ptr& env, std::vector<instruction_ptr>& into) c
for(auto& constr_pair : type->constructors) {
if(jump_instruction->tag_mappings.find(constr_pair.second.tag) ==
jump_instruction->tag_mappings.end())
throw type_error("non-total pattern");
throw type_error("non-total pattern", loc);
}
}
@ -421,13 +421,13 @@ void pattern_constr::find_variables(std::set<std::string>& into) const {
void pattern_constr::typecheck(type_ptr t, type_mgr& mgr, type_env_ptr& env) const {
type_scheme_ptr constructor_type_scheme = env->lookup(constr);
if(!constructor_type_scheme) {
throw type_error(std::string("pattern using unknown constructor ") + constr);
throw type_error(std::string("pattern using unknown constructor ") + constr, loc);
}
type_ptr constructor_type = constructor_type_scheme->instantiate(mgr);
for(auto& param : params) {
type_arr* arr = dynamic_cast<type_arr*>(constructor_type.get());
if(!arr) throw type_error("too many parameters in constructor pattern");
if(!arr) throw type_error("too many parameters in constructor pattern", loc);
env->bind(param, arr->left);
constructor_type = arr->right;