Skip to content

Commit

Permalink
Fix issues caused by merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKeDer committed Jun 28, 2020
1 parent b64e56a commit 9a2ccc8
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/data_types/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::cell::RefCell;
use std::collections::HashMap;

use crate::data_types::*;
use crate::error_handler::{RuntimeError, ErrorLocation};
use crate::dove_callable::{DoveCallable, BuiltinFunction};
use crate::token::{Literals, DictKey};

Expand Down Expand Up @@ -31,7 +32,7 @@ fn dict_keys(dict: &Rc<RefCell<HashMap<DictKey, Literals>>>) -> impl DoveCallabl
}
}

Literals::Array(Rc::new(RefCell::new(res_raw)))
Ok(Literals::Array(Rc::new(RefCell::new(res_raw))))
})
}

Expand All @@ -45,7 +46,7 @@ fn dict_values(dict: &Rc<RefCell<HashMap<DictKey, Literals>>>) -> impl DoveCalla
res_raw.push(val.clone());
}

Literals::Array(Rc::new(RefCell::new(res_raw)))
Ok(Literals::Array(Rc::new(RefCell::new(res_raw))))
})
}

Expand All @@ -58,18 +59,16 @@ fn dict_remove(dict: &Rc<RefCell<HashMap<DictKey, Literals>>>) -> impl DoveCalla
// Convert key to DictKey type.
let dict_key = match key {
Literals::String(s) => DictKey::StringKey(s),
Literals::Number(n) => {
if n.fract() != 0.0 { panic!("Expected an integer key. "); }
DictKey::NumberKey(n as usize)
},
_ => {
panic!("Expected a string or an integer key.")
}
Literals::Number(n) if n.fract() != 0.0 => DictKey::NumberKey(n as isize),
_ => return Err(RuntimeError::new(
ErrorLocation::Unspecified,
"Expected a string or an integer key.".to_string(),
))
};

match dict.borrow_mut().remove(&dict_key) {
Some(v) => v,
None => Literals::Nil,
Some(v) => Ok(v),
None => Ok(Literals::Nil),
}
})
}

0 comments on commit 9a2ccc8

Please sign in to comment.