[Evaluator]
Remove update method; a remnant of the assign expression
When using the get method, Borrow String
Add Result if an array is not found
use super::object::{Object, Array};
-
+use super::errors::EnvironmentError;
use noirc_frontend::analyser::scope::{Scope as GenericScope, ScopeTree as GenericScopeTree, ScopeForest as GenericScopeForest};
type Scope = GenericScope<String, Object>;
@@ -33,25 +33,17 @@ impl Environment {
let scope = self.0.get_mut_scope();
scope.add_key_value(name.clone(),object);
}
- pub fn update(&mut self, name: String, object: Object) {
-
- panic!("Re-assignment feature is currently being rolled-back. Note however that you can only re-assign what is to become Field");
- let scope = self.0.current_scope_tree();
- let old_object = scope.find_key(&name).unwrap();
-
- *old_object = object;
- }
- pub fn get(&mut self, name: String) -> Object {
+ pub fn get(&mut self, name: &String) -> Object {
let scope = self.0.current_scope_tree();
- scope.find_key(&name).unwrap().clone()
+ scope.find_key(name).unwrap().clone()
}
- pub fn get_array(&mut self, name: String) -> Array {
+ pub fn get_array(&mut self, name: &String) -> Result<Array, EnvironmentError> {
let poly = self.get(name);
match poly {
- Object::Array(arr) => arr,
- _=> panic!("Cannot find an array with that name")
+ Object::Array(arr) => Ok(arr),
+ k => Err(EnvironmentError::ArrayNotFound{name : name.to_owned(), found_type : k.r#type().to_owned()})
}
}
}
