From 135baed51ef1cec1d3886c44d8f5ead87ce90866 Mon Sep 17 00:00:00 2001 From: Lorenzo Torres Date: Thu, 4 Dec 2025 22:45:50 +0100 Subject: [PATCH] checking if a type was already defined --- examples/hello_world.l | 4 ++-- sema.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/hello_world.l b/examples/hello_world.l index 61cebe9..d1ab425 100644 --- a/examples/hello_world.l +++ b/examples/hello_world.l @@ -3,9 +3,9 @@ struct a { } struct b { - c ciao, + u32 ciao, } struct c { - b test, + u32 test, } diff --git a/sema.c b/sema.c index 18aac86..27122f4 100644 --- a/sema.c +++ b/sema.c @@ -85,6 +85,9 @@ static void order_type(sema *s, ast_node *node) graph_node = arena_alloc(s->allocator, sizeof(pair)); graph_node->node.in = NULL; graph_node->node.out = NULL; + } else if (graph_node->complete) { + error(node, "type already defined."); + return; } graph_node->node.value = t; @@ -101,6 +104,7 @@ static void order_type(sema *s, ast_node *node) p->node.out = NULL; p->node.in = NULL; p->node.value = NULL; + p->complete = false; shput(types, name, p); } @@ -111,6 +115,7 @@ static void order_type(sema *s, ast_node *node) } shput(types, k, graph_node); + graph_node->complete = true; } }