From 457be797a2c168930d6dc4a7894470b030d9101b Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 2 Sep 2021 22:17:45 +0800 Subject: [PATCH 1/4] Fixed bug in using error variable within `catch` block. --- CHANGELOG.md | 9 +++++++++ src/parse.rs | 1 + tests/throw.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a8d41a..7084cebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Rhai Release Notes ================== +Version 1.0.3 +============= + +Bug fixes +--------- + +* Fixed bug with `catch` variable used in `catch` block. + + Version 1.0.2 ============= diff --git a/src/parse.rs b/src/parse.rs index a98154cc..e383d597 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -2915,6 +2915,7 @@ fn parse_try_catch( } let name = state.get_identifier(name); + state.stack.push((name.clone(), AccessMode::ReadWrite)); Some(Ident { name, pos }) } else { None diff --git a/tests/throw.rs b/tests/throw.rs index 0b8b717f..a93cfd04 100644 --- a/tests/throw.rs +++ b/tests/throw.rs @@ -29,6 +29,50 @@ fn test_try_catch() -> Result<(), Box> { 123 ); + #[cfg(not(feature = "no_function"))] + assert_eq!( + engine.eval::( + " + fn foo(x) { try { throw 42; } catch (x) { return x; } } + foo(0) + " + )?, + 42 + ); + + assert_eq!( + engine.eval::( + " + let err = 123; + let x = 0; + try { throw 42; } catch(err) { return err; } + " + )?, + 42 + ); + + assert_eq!( + engine.eval::( + " + let foo = 123; + let x = 0; + try { throw 42; } catch(err) { return foo; } + " + )?, + 123 + ); + + assert_eq!( + engine.eval::( + " + let foo = 123; + let x = 0; + try { throw 42; } catch(err) { return err; } + " + )?, + 42 + ); + #[cfg(not(feature = "unchecked"))] assert!(matches!( *engine From 11390af7c9cd8f3c171af0b02c0271946cae2314 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 2 Sep 2021 22:19:22 +0800 Subject: [PATCH 2/4] Add bug-fixes to CI. --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 24607668..7863933d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - bug-fixes - plugins pull_request: {} From cdcca563ed9ca579b34735a8471c4e23af2c0911 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 2 Sep 2021 22:20:00 +0800 Subject: [PATCH 3/4] Remove plugins from CI. --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7863933d..8e97e90a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,6 @@ on: branches: - master - bug-fixes - - plugins pull_request: {} jobs: From 29806831539cd3b1f1680d5e2132d1cd81120fc9 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 2 Sep 2021 22:44:33 +0800 Subject: [PATCH 4/4] Fix test output. --- codegen/ui_tests/rhai_fn_non_clonable_return.stderr | 7 ++++--- codegen/ui_tests/rhai_mod_non_clonable_return.stderr | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr index 28d43e99..d614b6bc 100644 --- a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `NonClonable: Clone` is not satisfied 11 | pub fn test_fn(input: f32) -> NonClonable { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable` | - ::: $WORKSPACE/src/dynamic.rs +note: required by a bound in `rhai::Dynamic::from` + --> $DIR/dynamic.rs:1043:30 | - | pub fn from(mut value: T) -> Self { - | ----- required by this bound in `rhai::Dynamic::from` +1043 | pub fn from(mut value: T) -> Self { + | ^^^^^ required by this bound in `rhai::Dynamic::from` diff --git a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr index 73ba7569..a660003d 100644 --- a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `NonClonable: Clone` is not satisfied 12 | pub fn test_fn(input: f32) -> NonClonable { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable` | - ::: $WORKSPACE/src/dynamic.rs +note: required by a bound in `rhai::Dynamic::from` + --> $DIR/dynamic.rs:1043:30 | - | pub fn from(mut value: T) -> Self { - | ----- required by this bound in `rhai::Dynamic::from` +1043 | pub fn from(mut value: T) -> Self { + | ^^^^^ required by this bound in `rhai::Dynamic::from`