From 34357163cdc5f91f034272d1d77405f1daa0d049 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 9 Sep 2020 15:15:25 -0700 Subject: [PATCH] Print locations in non-unification type errors. --- 13/ast.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/13/ast.cpp b/13/ast.cpp index 0beec14..10db5cb 100644 --- a/13/ast.cpp +++ b/13/ast.cpp @@ -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(input_type.get())) || !dynamic_cast(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& 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& 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& 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(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;