Fix a bug in setting global variables.

Setting a global variable would clobber any local variables with the
same name.
This commit is contained in:
Natalie Weizenbaum 2016-11-01 14:08:25 -07:00
parent 9d4efd2120
commit 17e29fd06e

View File

@ -166,7 +166,9 @@ class Environment {
/// previous scope. If it's undefined, it'll set it in the current scope.
void setVariable(String name, Value value, {bool global: false}) {
if (global || _variables.length == 1) {
_variableIndices[name] = 0;
// Don't set the index if there's already a variable with the given name,
// since local accesses should still return the local variable.
_variableIndices.putIfAbsent(name, () => 0);
_variables.first[name] = value;
return;
}