diff --git a/CHANGELOG.md b/CHANGELOG.md index bf69d3f..6f94140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Version 3.0.1 : Bug fix +Fix stackoverflow on custom function call with same name + # Version 3.0.0 : Symbolic calculation! Version 3.0.0, at last! (if you've seen the PR for it it's been sitting for more than three weeks!) diff --git a/Cargo.lock b/Cargo.lock index 3f3b36e..b1ed428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,7 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mini-calc" -version = "3.0.0" +version = "3.0.1" dependencies = [ "ansi_term", "atty", diff --git a/Cargo.toml b/Cargo.toml index 66bdd89..db06af7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mini-calc" -version = "3.0.0" +version = "3.0.1" license = "GPL-3.0-or-later" description = "A fully-featured minimalistic configurable rust calculator" homepage = "https://calc.nwa2coco.fr" diff --git a/src/configuration/loader.rs b/src/configuration/loader.rs index 5417676..399053a 100644 --- a/src/configuration/loader.rs +++ b/src/configuration/loader.rs @@ -131,7 +131,7 @@ pub fn load_color(string: String) -> Color { pub fn replace_variable(str: String) -> String { str.replace("%author%", "Charlotte Thomas") - .replace("%version%", "v3.0.0") + .replace("%version%", "v3.0.1") .to_string() } diff --git a/src/functions/function.rs b/src/functions/function.rs index c51daf0..19e9e42 100644 --- a/src/functions/function.rs +++ b/src/functions/function.rs @@ -56,8 +56,9 @@ pub fn apply_operator_reverse( } pub fn assign(s: Parameters, s2: Parameters) -> (String, Parameters) { - match s { - Identifier(s) => (s, s2), + match (s, s2.clone()) { + (Identifier(s), Identifier(s2)) if s == s2 => ("".to_string(), Identifier(s2)), + (Identifier(s), _) => (s, s2), _ => ("".to_string(), s2), } } diff --git a/src/interpreting/stdlib.rs b/src/interpreting/stdlib.rs index 8c602c9..92a4ef5 100644 --- a/src/interpreting/stdlib.rs +++ b/src/interpreting/stdlib.rs @@ -75,9 +75,16 @@ pub fn exec( }, } } - names.iter().zip(lst).for_each(|(name, param)| { - sram.insert(name.to_string(), param); - }); + names + .iter() + .zip(lst) + .filter(|(name, param)| match param { + Parameters::Identifier(s) => s.as_str() != name.as_str(), + _ => true, + }) + .for_each(|(name, param)| { + sram.insert(name.to_string(), param); + }); interpret(ast, &mut sram, &mut HashMap::new()) } } diff --git a/src/main.rs b/src/main.rs index 364154a..6271ee0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -263,7 +263,7 @@ fn handle_config(line: &str, config: Config) -> (String, Option) { fn main() { let mut args: Args = env::args(); - let version: String = "v3.0.0".to_string(); + let version: String = "v3.0.1".to_string(); if args.len() > 1 || !atty::is(Stream::Stdin) { let mut a = vec![];