diff --git a/src/cstatic.c b/src/cstatic.c index 71bb36d..5abb140 100644 --- a/src/cstatic.c +++ b/src/cstatic.c @@ -412,14 +412,13 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz type_free(t); free(t); } } - + int status = cstatic_check(self, ast->children.data[ast->children.size - 1], inner_table, msg, size ); - symtable_free(inner_table); free(inner_table); @@ -430,6 +429,11 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz if (ast->type == NODE_RETURN) { type* ret_ty = cstatic_resolve_new(self, sym, ast); + + int status_inner = cstatic_check_children(self, ast, sym, msg, size); + + if (!status_inner) { return status_inner; } + type* fun_ty = cstatic_top_fun(self)->ty; type* fun_res = NULL; @@ -473,10 +477,25 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz { char const* fun_name = ast->children.data[0]->value; symentry* entry = symtable_find(sym, fun_name); - assert(entry); - type* fun_type = entry->ty; + type* fun_type = NULL; + + if (entry) + { + fun_type = entry->ty; + } + else + { + fun_info* info = cstatic_top_fun(self); + + if (info && info->name) + { + fun_type = info->ty; + } + } + assert(fun_type); + node* args = ast->children.data[1]; size_t arity = 0; @@ -556,6 +575,7 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz || ast->type == NODE_FUNDECL) { char const* name = ast->children.data[0]->value; + symentry* entry = symtable_find(sym, name); if (entry && entry->scope >= sym->scope) { diff --git a/tests/test_fun.wuz b/tests/test_fun.wuz index 11a1143..8651211 100644 --- a/tests/test_fun.wuz +++ b/tests/test_fun.wuz @@ -55,3 +55,13 @@ fun i (n as int) as int end assert 27 == h 3, i + +fun j (n as int) as int + fun j_inner (n as int) as int + return n * 2 + end + + return j_inner (j_inner n) +end + +assert 32 == j 8