diff options
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | symbol.c | 4 |
2 files changed, 7 insertions, 0 deletions
@@ -229,6 +229,9 @@ assign(Datum left, Datum right) if(left.symbol->setfn != nil) left.symbol->setfn(right); else{ + /* re-assign the symbol to one that is sure to be local. This enables shadowing */ + left.symbol = getsym(left.symbol->name, 1); + if(left.symbol->undefined == 0 && left.symbol->value.tag == ArrayTag) freearray(left.symbol->value.array); left.symbol->value = right; @@ -38,6 +38,10 @@ getsym(Rune *name, int fresh) done = 1; }while(!done && !fresh); + /* make sure to allocate in the most local scope if the symbol is not found */ + if(currentdfn) + tab = currentdfn->symtab; + tab->nsyms++; tab->syms = realloc(tab->syms, sizeof(Symbol *) * tab->nsyms); tab->syms[tab->nsyms-1] = emalloc(sizeof(Symbol)); |