diff --git a/code/compiler/13/ast.cpp b/code/compiler/13/ast.cpp index a59e995..8a99486 100644 --- a/code/compiler/13/ast.cpp +++ b/code/compiler/13/ast.cpp @@ -43,7 +43,10 @@ void ast_lid::find_free(std::set& into) { type_ptr ast_lid::typecheck(type_mgr& mgr, type_env_ptr& env) { this->env = env; - return env->lookup(id)->instantiate(mgr); + type_scheme_ptr lid_type = env->lookup(id); + if(!lid_type) + throw type_error(std::string("unknown identifier ") + id, loc); + return lid_type->instantiate(mgr); } void ast_lid::translate(global_scope& scope) { @@ -69,7 +72,10 @@ void ast_uid::find_free(std::set& into) { type_ptr ast_uid::typecheck(type_mgr& mgr, type_env_ptr& env) { this->env = env; - return env->lookup(id)->instantiate(mgr); + type_scheme_ptr uid_type = env->lookup(id); + if(!uid_type) + throw type_error(std::string("unknown constructor ") + id, loc); + return uid_type->instantiate(mgr); } void ast_uid::translate(global_scope& scope) {