diff --git a/src/cstatic.c b/src/cstatic.c index abef04b..71bb36d 100644 --- a/src/cstatic.c +++ b/src/cstatic.c @@ -63,7 +63,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast) type_new_from_node( ast->children.data[i]->children.data[1] ); - type_add_sub_type(ty, param_ty); type_free(param_ty); free(param_ty); @@ -74,7 +73,7 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast) && ast->children.data[i]->type == NODE_FUN_RET) { node* ret = ast->children.data[i]; - + for (size_t i=0; ichildren.size; i++) { type* r = type_new_from_node(ret->children.data[i]); @@ -90,7 +89,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast) if (ast->type == NODE_CALL) { char const* fun_name = ast->children.data[0]->value; - symentry* entry = symtable_find(sym, fun_name); fun_info* info = NULL; @@ -121,17 +119,18 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast) assert(fun_type); - + size_t ret_count = fun_type->sub_types.size; if (ret_count > 0) { - type* ret_type = fun_type->sub_types.data[ret_count - 1]; + type* ret_type = + fun_type->sub_types.data[ret_count - 1]; + assert(ret_type); - + if (ret_type->kind == KIND_RETURN) { - type* res = type_new_clone(ret_type); res->kind = KIND_CONJUNCTION; return res; @@ -190,8 +189,6 @@ type* cstatic_resolve_new(cstatic* self, symtable* sym, node* ast) || ast->type == NODE_CONSTDECL || ast->type == NODE_FUNDECL) { - char* name = ast->children.data[0]->value; - printf("-> %s\n", name); type* ty = cstatic_resolve_new(self, sym, ast->children.data[1]); @@ -448,7 +445,7 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz } assert(fun_res); - + assert(ret_ty); int status = cstatic_check_same_type_ptr( self, ast, @@ -458,7 +455,7 @@ int cstatic_check(cstatic* self, node* ast, symtable* sym, char* msg, size_t siz msg, size ); - + if (status) { if (fun_res) diff --git a/src/type.c b/src/type.c index e1aff9c..572fefa 100644 --- a/src/type.c +++ b/src/type.c @@ -35,6 +35,7 @@ type* type_init_from_node(node* root) for (size_t i=0; i< rets->children.size; i++) { type* t = type_new_from_node(rets->children.data[i]); + t->kind = KIND_RETURN; type_add_sub_type(ty, t); type_free(t); free(t); } diff --git a/tests/test_fun.wuz b/tests/test_fun.wuz index 47779d3..11a1143 100644 --- a/tests/test_fun.wuz +++ b/tests/test_fun.wuz @@ -46,3 +46,12 @@ end assert 120 == f 5 +fun h (n as int, m as fun) as int + return (m (m n)) +end + +fun i (n as int) as int + return n * 3 +end + +assert 27 == h 3, i