Fix closures

This commit is contained in:
ala89 2024-01-04 22:07:57 +01:00
parent aa25c31bcf
commit a40fc2f2d8

View File

@ -79,6 +79,14 @@ void Memory::update(string identifier, EvalResult value) {
scope.vars[identifier].initialized = true; scope.vars[identifier].initialized = true;
return; return;
} }
if (scope.type == ScopeType::Function) {
Closure closure = std::get<1>(std::get<Function>(scope.fn->value));
if (closure.contains(identifier)) {
MemoryVar& var = closure.at(identifier);
var.value = value;
var.initialized = true;
}
}
} }
throw exception(); throw exception();