Skip to content

Commit

Permalink
fix: fixed an issue that prevented capturing variables (when creating…
Browse files Browse the repository at this point in the history
… a closure) declared inside a module-level loop
  • Loading branch information
jacopodl committed Sep 20, 2023
1 parent 4bf908a commit 9d74218
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions argon/lang/translation_unit.cpp
Expand Up @@ -49,9 +49,12 @@ bool TranslationUnit::IsFreeVar(String *id) const {
// in turn then this is a free variable
SymbolT *sym;

for (TranslationUnit *tu = this->prev; tu != nullptr && tu->symt->type == SymbolType::FUNC; tu = tu->prev) {
for (TranslationUnit *tu = this->prev; tu != nullptr; tu = tu->prev) {
if ((sym = SymbolLookup(tu->symt, id)) != nullptr) {
if (sym->declared || sym->free) {
// WARNING: sym->nested must be greater than 0,
// otherwise this is a global variable.
if (sym->type == SymbolType::VARIABLE &&
sym->nested > 0 && (sym->declared || sym->free)) {
Release(sym);

return true;
Expand Down

0 comments on commit 9d74218

Please sign in to comment.