checking if a type was already defined

This commit is contained in:
Lorenzo Torres 2025-12-04 22:45:50 +01:00
parent 2f5dfe381e
commit 135baed51e
2 changed files with 7 additions and 2 deletions

View file

@ -3,9 +3,9 @@ struct a {
} }
struct b { struct b {
c ciao, u32 ciao,
} }
struct c { struct c {
b test, u32 test,
} }

5
sema.c
View file

@ -85,6 +85,9 @@ static void order_type(sema *s, ast_node *node)
graph_node = arena_alloc(s->allocator, sizeof(pair)); graph_node = arena_alloc(s->allocator, sizeof(pair));
graph_node->node.in = NULL; graph_node->node.in = NULL;
graph_node->node.out = NULL; graph_node->node.out = NULL;
} else if (graph_node->complete) {
error(node, "type already defined.");
return;
} }
graph_node->node.value = t; graph_node->node.value = t;
@ -101,6 +104,7 @@ static void order_type(sema *s, ast_node *node)
p->node.out = NULL; p->node.out = NULL;
p->node.in = NULL; p->node.in = NULL;
p->node.value = NULL; p->node.value = NULL;
p->complete = false;
shput(types, name, p); shput(types, name, p);
} }
@ -111,6 +115,7 @@ static void order_type(sema *s, ast_node *node)
} }
shput(types, k, graph_node); shput(types, k, graph_node);
graph_node->complete = true;
} }
} }