diff options
Diffstat (limited to 'scope.c')
-rw-r--r-- | scope.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -1,5 +1,8 @@ #define SCOPE_FLAG_CHECK_REDECL 0x0001 + +static void val_free(Value *v, Type *t); + static bool add_ident_decls(Block *b, Declaration *d, U32 flags) { bool ret = true; arr_foreach(d->idents, Identifier, ident) { @@ -20,17 +23,16 @@ static bool add_ident_decls(Block *b, Declaration *d, U32 flags) { } static void remove_ident_decls(Block *b, Declaration *d) { + U64 i = 0; arr_foreach(d->idents, Identifier, ident) { IdentTree *id_info = *ident; IdentDecl **decls = &id_info->decls; IdentDecl *last_decl = arr_last(*decls); if (last_decl && last_decl->scope == b) { if ((last_decl->flags & IDECL_FLAG_HAS_VAL) - /* don't free const arrays (there's only one per decl) */ - && !(last_decl->decl->flags & DECL_FLAG_CONST) - && last_decl->decl->type.kind == TYPE_ARR) { - /* free array on stack */ - free(last_decl->val.arr); + /* don't free const vals (there's only one per decl) */ + && !(last_decl->decl->flags & DECL_FLAG_CONST)) { + val_free(&last_decl->decl->val, d->type.kind == TYPE_TUPLE ? &d->type.tuple[i++] : &d->type); } arr_remove_last(decls); /* remove that declaration */ } |