From a40fc2f2d87247da9e96597eb3c5716a79688c18 Mon Sep 17 00:00:00 2001 From: ala89 Date: Thu, 4 Jan 2024 22:07:57 +0100 Subject: [PATCH] Fix closures --- src/memory.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/memory.cpp b/src/memory.cpp index 9b37351..1f3f620 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -79,6 +79,14 @@ void Memory::update(string identifier, EvalResult value) { scope.vars[identifier].initialized = true; return; } + if (scope.type == ScopeType::Function) { + Closure closure = std::get<1>(std::get(scope.fn->value)); + if (closure.contains(identifier)) { + MemoryVar& var = closure.at(identifier); + var.value = value; + var.initialized = true; + } + } } throw exception();