Fix bug in closure capture for no_object.

This commit is contained in:
Stephen Chung 2020-08-23 17:46:39 +08:00
parent e2f271644a
commit 7cd345b128
2 changed files with 5 additions and 4 deletions

View File

@ -9,6 +9,7 @@ Bug fixes
* `Engine::compile_expression`, `Engine::eval_expression` etc. no longer parse anonymous functions and closures.
* Imported modules now work inside closures.
* Closures that capture now work under `no_object`.
Version 0.18.2

View File

@ -3167,6 +3167,8 @@ fn make_curry_from_externals(
let num_externals = externals.len();
let mut args: StaticVec<_> = Default::default();
args.push(fn_expr);
#[cfg(not(feature = "no_closure"))]
externals.iter().for_each(|(var_name, pos)| {
args.push(Expr::Variable(Box::new((
@ -3182,9 +3184,9 @@ fn make_curry_from_externals(
args.push(Expr::Variable(Box::new(((var_name, pos), None, 0, None))));
});
let hash = calc_fn_hash(empty(), KEYWORD_FN_PTR_CURRY, num_externals, empty());
let hash = calc_fn_hash(empty(), KEYWORD_FN_PTR_CURRY, num_externals + 1, empty());
let fn_call = Expr::FnCall(Box::new((
let expr = Expr::FnCall(Box::new((
(KEYWORD_FN_PTR_CURRY.into(), false, false, pos),
None,
hash,
@ -3192,8 +3194,6 @@ fn make_curry_from_externals(
None,
)));
let expr = Expr::Dot(Box::new((fn_expr, fn_call, pos)));
// If there are captured variables, convert the entire expression into a statement block,
// then insert the relevant `Share` statements.
#[cfg(not(feature = "no_closure"))]