From a24458a04254d7fd3f613ffc666027de359af0bf Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Wed, 7 Oct 2020 16:57:48 +0200
Subject: [PATCH] Add missing tests for clean-up of local variables within `if`
 blocks

---
 src/language/node_processor/IfProcessor.hpp |  4 ++--
 tests/test_IfProcessor.cpp                  | 24 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/language/node_processor/IfProcessor.hpp b/src/language/node_processor/IfProcessor.hpp
index 1a76e3068..18d87bb89 100644
--- a/src/language/node_processor/IfProcessor.hpp
+++ b/src/language/node_processor/IfProcessor.hpp
@@ -3,6 +3,7 @@
 
 #include <language/ast/ASTNode.hpp>
 #include <language/node_processor/INodeProcessor.hpp>
+#include <language/utils/SymbolTable.hpp>
 
 class IfProcessor final : public INodeProcessor
 {
@@ -39,8 +40,7 @@ class IfProcessor final : public INodeProcessor
       }
     }
 
-    if (m_node.children[0]->m_symbol_table != m_node.m_symbol_table)
-      m_node.children[0]->m_symbol_table->clearValues();
+    Assert(m_node.children[0]->m_symbol_table == m_node.m_symbol_table);
     return {};
   }
 
diff --git a/tests/test_IfProcessor.cpp b/tests/test_IfProcessor.cpp
index ccade1625..71fc76684 100644
--- a/tests/test_IfProcessor.cpp
+++ b/tests/test_IfProcessor.cpp
@@ -102,6 +102,30 @@ if(false) {
     CHECK_IF_PROCESSOR_RESULT(data, "i", 2ul);
   }
 
+  SECTION("simple if(true) with local variable")
+  {
+    std::string_view data = R"(
+let i:N, i = 0;
+if(true) {
+  let j:N, j = 1;
+  i = j;
+}
+)";
+    CHECK_IF_PROCESSOR_RESULT(data, "i", 1ul);
+  }
+
+  SECTION("simple if(false) with else local variable")
+  {
+    std::string_view data = R"(
+let i:N, i = 0;
+if(false) {} else {
+  let j:N, j = 1;
+  i = j;
+}
+)";
+    CHECK_IF_PROCESSOR_RESULT(data, "i", 1ul);
+  }
+
   SECTION("errors")
   {
     SECTION("bad test type")
-- 
GitLab