From 0033c4b8148b3eb777984638ac9f1a8f19c1039f Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 15 Dec 2023 10:38:36 +0100 Subject: [PATCH] Fix variables tests --- src/analysis.cpp | 4 ++-- test/variables.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/analysis.cpp b/src/analysis.cpp index a8daae7..33ee186 100644 --- a/src/analysis.cpp +++ b/src/analysis.cpp @@ -209,7 +209,7 @@ AnalysisResult analyze(Node &ast, Memory &memory) { Token token = get(node.children[1]); string identifier = get(token.data); - if (memory.contains(identifier)) + if (memory.contains_top(identifier)) throw RuntimeError("Already defined identifier \""+identifier+"\"", token.pos); Type type = try_string_to_type(type_string, type_token.pos); @@ -224,7 +224,7 @@ AnalysisResult analyze(Node &ast, Memory &memory) { Token token = get(node.children[1]); string identifier = get(token.data); - if (memory.contains(identifier)) + if (memory.contains_top(identifier)) throw TypeError("Already defined identifier \""+identifier+"\"", token.pos); Type type = try_string_to_type(type_string, type_token.pos); diff --git a/test/variables.cpp b/test/variables.cpp index dddac99..7ce4578 100644 --- a/test/variables.cpp +++ b/test/variables.cpp @@ -3,12 +3,14 @@ #include "../src/include/memory.h" #include "../src/include/tokenize.h" #include "../src/include/parser.h" +#include "../src/include/analysis.h" #include "../src/include/interpreter.h" EvalResult execute(string s) { Memory memory;; vector tokens = tokenize({ s }); Node ast = parse(tokens); + analyze(ast, memory); EvalResult res = eval(ast, memory); return res;