broken! added return nodes
This commit is contained in:
parent
f7689a3f54
commit
89e0d41fd9
4 changed files with 173 additions and 20 deletions
5
sema.c
5
sema.c
|
|
@ -316,6 +316,7 @@ static void create_prototype(sema *s, ast_node *node)
|
|||
{
|
||||
prototype *p = arena_alloc(s->allocator, sizeof(prototype));
|
||||
p->name = intern_string(s, node->expr.function.name, node->expr.function.name_len);
|
||||
node->expr.function.name = p->name;
|
||||
if (shget(prototypes, p->name)) {
|
||||
error(node, "function already defined.");
|
||||
}
|
||||
|
|
@ -668,7 +669,7 @@ static void check_statement(sema *s, ast_node *node)
|
|||
char *name = NULL;
|
||||
switch(node->type) {
|
||||
case NODE_RETURN:
|
||||
if (!match(get_expression_type(s, node->expr.ret.value), current_return)) {
|
||||
if (!can_cast(get_expression_type(s, node->expr.ret.value), current_return) && !match(get_expression_type(s, node->expr.ret.value), current_return)) {
|
||||
error(node, "return type doesn't match function's one.");
|
||||
}
|
||||
break;
|
||||
|
|
@ -728,7 +729,7 @@ static void check_function(sema *s, ast_node *f)
|
|||
while (param) {
|
||||
type *p_type = get_type(s, param->type);
|
||||
char *t_name = intern_string(s, param->name, param->name_len);
|
||||
|
||||
param->name = t_name;
|
||||
ast_node *param_node = arena_alloc(s->allocator, sizeof(ast_node));
|
||||
param_node->type = NODE_VAR_DECL;
|
||||
param_node->expr_type = p_type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue