handle LIST nodes properly in flattening

This commit is contained in:
2026-02-27 11:10:44 +01:00
parent 3413f6966d
commit e1f59fb954

View File

@@ -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;
}