Fill variable index on captured variables in closures.
This commit is contained in:
parent
2f88757efe
commit
d55b5a91f7
@ -1441,7 +1441,7 @@ impl Engine {
|
|||||||
..settings
|
..settings
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = self.parse_anon_fn(input, &mut new_state, lib, new_settings);
|
let result = self.parse_anon_fn(input, &mut new_state, state, lib, new_settings);
|
||||||
|
|
||||||
// Restore parse state
|
// Restore parse state
|
||||||
state.interned_strings = new_state.interned_strings;
|
state.interned_strings = new_state.interned_strings;
|
||||||
@ -1464,7 +1464,7 @@ impl Engine {
|
|||||||
// Under Strict Variables mode, this is not allowed.
|
// Under Strict Variables mode, this is not allowed.
|
||||||
Err(PERR::VariableUndefined(name.to_string()).into_err(*pos))
|
Err(PERR::VariableUndefined(name.to_string()).into_err(*pos))
|
||||||
} else {
|
} else {
|
||||||
Ok::<_, ParseError>(())
|
Ok(())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
@ -3655,6 +3655,8 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
fn make_curry_from_externals(
|
fn make_curry_from_externals(
|
||||||
state: &mut ParseState,
|
state: &mut ParseState,
|
||||||
|
parent: &mut ParseState,
|
||||||
|
lib: &FnLib,
|
||||||
fn_expr: Expr,
|
fn_expr: Expr,
|
||||||
externals: StaticVec<crate::ast::Ident>,
|
externals: StaticVec<crate::ast::Ident>,
|
||||||
pos: Position,
|
pos: Position,
|
||||||
@ -3674,12 +3676,14 @@ impl Engine {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|crate::ast::Ident { name, pos }| {
|
.map(|crate::ast::Ident { name, pos }| {
|
||||||
#[cfg(not(feature = "no_module"))]
|
let (index, is_func) = parent.access_var(&name, lib, pos);
|
||||||
let ns = crate::ast::Namespace::NONE;
|
let idx = match index {
|
||||||
#[cfg(feature = "no_module")]
|
Some(n) if !is_func && n.get() <= u8::MAX as usize => {
|
||||||
let ns = ();
|
NonZeroU8::new(n.get() as u8)
|
||||||
|
}
|
||||||
Expr::Variable((None, ns, 0, name).into(), None, pos)
|
_ => None,
|
||||||
|
};
|
||||||
|
Expr::Variable((index, Default::default(), 0, name).into(), idx, pos)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -3719,6 +3723,7 @@ impl Engine {
|
|||||||
&self,
|
&self,
|
||||||
input: &mut TokenStream,
|
input: &mut TokenStream,
|
||||||
state: &mut ParseState,
|
state: &mut ParseState,
|
||||||
|
parent: &mut ParseState,
|
||||||
lib: &mut FnLib,
|
lib: &mut FnLib,
|
||||||
settings: ParseSettings,
|
settings: ParseSettings,
|
||||||
) -> ParseResult<(Expr, ScriptFnDef)> {
|
) -> ParseResult<(Expr, ScriptFnDef)> {
|
||||||
@ -3815,7 +3820,8 @@ impl Engine {
|
|||||||
let expr = Expr::DynamicConstant(Box::new(fn_ptr.into()), settings.pos);
|
let expr = Expr::DynamicConstant(Box::new(fn_ptr.into()), settings.pos);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
let expr = Self::make_curry_from_externals(state, expr, externals, settings.pos);
|
let expr =
|
||||||
|
Self::make_curry_from_externals(state, parent, lib, expr, externals, settings.pos);
|
||||||
|
|
||||||
Ok((expr, script))
|
Ok((expr, script))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user