Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Feb 11, 2024
1 parent d87eb2a commit 45bfdb6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl Engine {
Some(Box::new(crate::module::resolvers::FileModuleResolver::new()));
}

// Turn on the strings interner
engine.set_max_strings_interned(MAX_STRINGS_INTERNED);

// default print/debug implementations
Expand All @@ -297,6 +298,7 @@ impl Engine {
}));
}

// Register the standard package
engine.register_global_module(StandardPackage::new().as_shared_module());

engine
Expand Down
9 changes: 1 addition & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,18 +1474,14 @@ impl Engine {
#[cfg(not(feature = "no_function"))]
Token::Pipe | Token::Or if settings.has_option(LangOptions::ANON_FN) => {
// Build new parse state
let new_interner = None;
let new_state = &mut ParseState::new(
state.external_constants,
new_interner,
state.interned_strings.as_deref_mut(),
state.input,
state.tokenizer_control.clone(),
state.lib,
);

// We move the strings interner to the new parse state object by swapping it...
std::mem::swap(&mut state.interned_strings, &mut new_state.interned_strings);

#[cfg(not(feature = "no_module"))]
{
// Do not allow storing an index to a globally-imported module
Expand Down Expand Up @@ -1518,9 +1514,6 @@ impl Engine {

let result = self.parse_anon_fn(new_state, new_settings.level_up()?);

// Restore the strings interner by swapping it back
std::mem::swap(&mut state.interned_strings, &mut new_state.interned_strings);

let (expr, fn_def, _externals) = result?;

#[cfg(not(feature = "no_closure"))]
Expand Down
7 changes: 5 additions & 2 deletions tests/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ fn test_closures() {
42
);

let x = engine.eval::<Dynamic>("let x = #{}; x.a = || x; x").unwrap();
println!("{x:?}");
#[cfg(not(feature = "unchecked"))]
{
let x = engine.eval::<Dynamic>("let x = #{}; x.a = || x; x").unwrap();
println!("{x:?}");
}
}

#[test]
Expand Down

0 comments on commit 45bfdb6

Please sign in to comment.