Skip to content

Commit adf813c

Browse files
committed
fix: resolve issue preventing correct access to closure variables
1 parent 8a1e8ee commit adf813c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

argon/lang/compiler2/compiler2.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ SymbolT *Compiler::IdentifierLookupOrCreate(String *id, argon::lang::compiler2::
6565

6666
auto *sym = this->unit_->symt->SymbolLookup(id, false);
6767
if (sym == nullptr) {
68-
if ((sym = this->unit_->symt->SymbolInsert(id, type)) == nullptr)
68+
auto freevar = this->unit_->IsFreeVar(id);
69+
70+
if ((sym = this->unit_->symt->SymbolInsert(id, type, freevar)) == nullptr)
6971
throw DatatypeException();
7072

71-
if (this->unit_->IsFreeVar(id)) {
73+
if (freevar) {
7274
dst = this->unit_->enclosed;
7375
sym->free = true;
7476
}

argon/lang/compiler2/symt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ bool SymbolT::NewNestedTable() {
108108
return true;
109109
}
110110

111-
SymbolT *SymbolT::SymbolInsert(String *s_name, SymbolType s_type) {
111+
SymbolT *SymbolT::SymbolInsert(String *s_name, SymbolType s_type, bool freevar) {
112112
SymbolT *sym = SymbolLookup(s_name, true);
113113
SymbolT *target = this;
114114

115-
if (this->stack != nullptr)
115+
if (!freevar && this->stack != nullptr)
116116
target = this->stack;
117117

118118
if (sym != nullptr) {

argon/lang/compiler2/symt.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ namespace argon::lang::compiler2 {
6262

6363
bool NewNestedTable();
6464

65-
SymbolT *SymbolInsert(vm::datatype::String *s_name, SymbolType s_type);
65+
SymbolT *SymbolInsert(vm::datatype::String *s_name, SymbolType s_type, bool freevar);
66+
67+
inline SymbolT *SymbolInsert(vm::datatype::String *s_name, SymbolType s_type) {
68+
return SymbolInsert(s_name, s_type, false);
69+
}
6670

6771
SymbolT *SymbolLookup(const vm::datatype::String *s_name, bool local) const;
6872
};

0 commit comments

Comments
 (0)