Merge branch 'bug-fixes'

This commit is contained in:
Stephen Chung 2021-09-02 22:49:17 +08:00
commit 65fbfe36e7
3 changed files with 51 additions and 0 deletions

View File

@ -28,6 +28,12 @@ Enhancements
* `Engine::register_type_XXX` are now available even under `no_object`.
Version 1.0.3
=============
* Fixed bug with `catch` variable used in `catch` block.
Version 1.0.2
=============

View File

@ -2929,6 +2929,7 @@ fn parse_try_catch(
}
let name = state.get_identifier(name);
state.stack.push((name.clone(), AccessMode::ReadWrite));
Some(Ident { name, pos })
} else {
None

View File

@ -29,6 +29,50 @@ fn test_try_catch() -> Result<(), Box<EvalAltResult>> {
123
);
#[cfg(not(feature = "no_function"))]
assert_eq!(
engine.eval::<INT>(
"
fn foo(x) { try { throw 42; } catch (x) { return x; } }
foo(0)
"
)?,
42
);
assert_eq!(
engine.eval::<INT>(
"
let err = 123;
let x = 0;
try { throw 42; } catch(err) { return err; }
"
)?,
42
);
assert_eq!(
engine.eval::<INT>(
"
let foo = 123;
let x = 0;
try { throw 42; } catch(err) { return foo; }
"
)?,
123
);
assert_eq!(
engine.eval::<INT>(
"
let foo = 123;
let x = 0;
try { throw 42; } catch(err) { return err; }
"
)?,
42
);
#[cfg(not(feature = "unchecked"))]
assert!(matches!(
*engine