From 6dd52ac18236f75853920096154aff987be47db2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 10 Oct 2019 17:59:44 -0700 Subject: [PATCH] Fix bug from small improvements --- 04/ast.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/04/ast.cpp b/04/ast.cpp index f8a88df..8880df2 100644 --- a/04/ast.cpp +++ b/04/ast.cpp @@ -97,10 +97,6 @@ type_ptr ast_case::typecheck(type_mgr& mgr, const type_env& env) const { type_ptr case_type = mgr.resolve(of->typecheck(mgr, env), var); type_ptr branch_type = mgr.new_type(); - if(!dynamic_cast(case_type.get())) { - throw type_error("attempting case analysis of non-data type"); - } - for(auto& branch : branches) { type_env new_env = env.scope(); branch->pat->match(case_type, mgr, new_env); @@ -108,6 +104,11 @@ type_ptr ast_case::typecheck(type_mgr& mgr, const type_env& env) const { mgr.unify(branch_type, curr_branch_type); } + case_type = mgr.resolve(case_type, var); + if(!dynamic_cast(case_type.get())) { + throw type_error("attempting case analysis of non-data type"); + } + return branch_type; }