improve error messages

- fix bug where `thread` function wouldn't error when being called on a non-function
- add compile error when a function in `try` is never used, because this is almost certainly a mistake and will cause mers to unexpectedly go down the "wrong" code path.
- some small changes so mers_lib can be used in another project
This commit is contained in:
Mark
2023-12-14 19:24:43 +01:00
parent 4cf349a680
commit 49d13d92cc
4 changed files with 125 additions and 44 deletions

View File

@@ -84,11 +84,19 @@ impl Config {
}
}
pub fn add_var(mut self, name: String, val: Data) -> Self {
pub fn add_var(self, name: String, val: Data) -> Self {
let t = val.get().as_type();
self.add_var_arc(name, Arc::new(RwLock::new(val)), t)
}
pub fn add_var_arc(
mut self,
name: String,
val: Arc<RwLock<Data>>,
val_type: crate::data::Type,
) -> Self {
self.info_parsed.scopes[0].init_var(name, (0, self.globals));
self.info_run.scopes[0].init_var(self.globals, Arc::new(RwLock::new(val)));
self.info_check.scopes[0].init_var(self.globals, t);
self.info_run.scopes[0].init_var(self.globals, val);
self.info_check.scopes[0].init_var(self.globals, val_type);
self.globals += 1;
self
}