From 17e29fd06e151fb17475bd12ff00724478008e93 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 1 Nov 2016 14:08:25 -0700 Subject: [PATCH] Fix a bug in setting global variables. Setting a global variable would clobber any local variables with the same name. --- lib/src/environment.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/environment.dart b/lib/src/environment.dart index 25b4830c..00dd4805 100644 --- a/lib/src/environment.dart +++ b/lib/src/environment.dart @@ -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; }