From 6d81538969cf667032640a810db7688d7323b126 Mon Sep 17 00:00:00 2001 From: Olle Sandberg Date: Tue, 3 Sep 2019 16:01:55 +0200 Subject: [PATCH] Allow to re-assign value to an existing binding. (#92) --- src/lib/exec.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/exec.rs b/src/lib/exec.rs index a09fb64f04..ceead58abe 100644 --- a/src/lib/exec.rs +++ b/src/lib/exec.rs @@ -316,8 +316,14 @@ impl Executor for Interpreter { let val = self.run(val_e)?; match ref_e.def { ExprDef::Local(ref name) => { - self.environment.create_mutable_binding(name.clone(), false); - self.environment.initialize_binding(name, val.clone()); + if *self.environment.get_binding_value(&name) != ValueData::Undefined { + // Binding already exists + self.environment + .set_mutable_binding(&name, val.clone(), true); + } else { + self.environment.create_mutable_binding(name.clone(), true); + self.environment.initialize_binding(name, val.clone()); + } } ExprDef::GetConstField(ref obj, ref field) => { let val_obj = self.run(obj)?;