From e1f59fb9542d31a382aafe419f5d96c9870d2b0c Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Fri, 27 Feb 2026 11:10:44 +0100 Subject: [PATCH] handle LIST nodes properly in flattening --- ps3/src/tree.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ps3/src/tree.c b/ps3/src/tree.c index 254bea5..289c104 100644 --- a/ps3/src/tree.c +++ b/ps3/src/tree.c @@ -265,12 +265,13 @@ static node_t* flatten_variable_declarations(node_t* block) assert(block->type == BLOCK); node_t *new_children = node_create(LIST, 0); - - for (int i = 0; i < block->n_children; i++) { - node_t *statement = block->children[i]; + node_t *list = block->children[0]; + for (int i = 0; i < list->n_children; i++) { + node_t *statement = list->children[i]; if (statement->type == LOCAL_VARIABLE_DECLARATION) { - for (int j = 0; j < statement->n_children; j++) { - node_t *var = statement->children[j]; + node_t *llist = statement->children[0]; + for (int j = 0; j < llist->n_children; j++) { + node_t *var = llist->children[j]; assert(var->type == LOCAL_VARIABLE); switch (var->n_children) { case 1: @@ -294,9 +295,9 @@ static node_t* flatten_variable_declarations(node_t* block) } } - free(block->children); - block->children = new_children; - + node_finalize(list); + block->children[0] = new_children; + return block; }