From cb888d722d9b9cb25b2614f9ebbfc7ac6d656331 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Thu, 25 Feb 2021 21:03:29 +0100
Subject: [PATCH] Fix a vicious bug in symbol table management

Functions identifiers are also stored in symbol tables.
When a block of code is left, all local variables are reset to avoid
useless memory consumption.

The problem was that locally defined functions lost their associate id
which is necessary to retrieve the function in the function
table. When a function was defined in a block, its id were set to 0...

Now functions identifiers are no more clean-up.
---
 src/language/utils/SymbolTable.hpp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/language/utils/SymbolTable.hpp b/src/language/utils/SymbolTable.hpp
index 6aa089bd8..772ac6564 100644
--- a/src/language/utils/SymbolTable.hpp
+++ b/src/language/utils/SymbolTable.hpp
@@ -267,12 +267,15 @@ class SymbolTable
   clearValues()
   {
     for (auto& symbol : m_symbol_list) {
-      std::visit(
-        [](auto&& value) {
-          using T = std::decay_t<decltype(value)>;
-          value   = T{};
-        },
-        symbol.attributes().value());
+      // local functions must kept their values (id)
+      if (symbol.attributes().dataType() != ASTNodeDataType::function_t) {
+        std::visit(
+          [](auto&& value) {
+            using T = std::decay_t<decltype(value)>;
+            value   = T{};
+          },
+          symbol.attributes().value());
+      }
     }
   }
 
-- 
GitLab