From e5cc80fb6a608aa1fbd0d6fabd1cf614a0fc004a Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 14:49:36 +0200 Subject: fix: add a workaround for redeclaration --- eval.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index fc6e6d7..cb967c2 100644 --- a/eval.c +++ b/eval.c @@ -222,6 +222,19 @@ static enum RunStatus declare(struct Machine* machine, const struct Node* node) return RUN_DONE; } +static enum RunStatus undeclare(struct Machine* machine, const struct Node* node) +{ + struct Variable* variable = find_variable(machine, node->name); + if (variable == NULL) + { + (void)complain(node, "cannot undeclare what was never declared"); + return RUN_FAILED; + } + + variable->declared = false; + return RUN_DONE; +} + static enum RunStatus emit(struct Machine* machine, const struct Node* node) { struct Type type; @@ -261,6 +274,7 @@ static enum RunStatus execute_one(struct Machine* machine, const struct Node* no switch (node->kind) { case STMT_DECLARE: return declare(machine, node); + case STMT_UNDECLARE: return undeclare(machine, node); case STMT_EMIT: return emit(machine, node); case STMT_STATIC_ASSERT: return static_assert_statement(machine, node); default: break; -- cgit v1.3