Skip to content
Snippets Groups Projects
Commit a24458a0 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add missing tests for clean-up of local variables within `if` blocks

parent 60c094b8
No related branches found
No related tags found
1 merge request!54Feature/language coverage
......@@ -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 {};
}
......
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment