From 1a05d5ff7a7e960331cc8cca1ca0ba6999f8cc56 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 10 Sep 2020 12:59:26 -0700 Subject: [PATCH] Add type errors to identifier nodes. --- code/compiler/13/ast.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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) {