overwrite protection for root env

This commit is contained in:
Pekka Laiho 2020-06-04 16:06:56 +07:00
parent 42441e78c2
commit 7c9ed7ca27

View File

@ -20,4 +20,14 @@ class Env extends Hash
throw new MadLispException("symbol $key not defined in env"); throw new MadLispException("symbol $key not defined in env");
} }
public function set(string $key, $value)
{
// Do not allow overwriting values in root env
if ($this->has($key) && $this->parent == null) {
throw new MadLispException("attempt to overwrite $key in root env");
}
return parent::set($key, $value);
}
} }