diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 08099edf..0b9ec418 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -618,6 +618,27 @@ impl AST { crate::func::native::shared_make_mut(&mut self.lib) .merge_filtered(&other.lib, &_filter); } + + #[cfg(not(feature = "no_module"))] + match ( + self.resolver.as_ref().map_or(0, |r| r.len()), + other.resolver.as_ref().map_or(0, |r| r.len()), + ) { + (_, 0) => (), + (0, _) => { + self.set_resolver(other.resolver.unwrap()); + } + (_, _) => { + let resolver = + crate::func::native::shared_make_mut(self.resolver.as_mut().unwrap()); + let other_resolver = + crate::func::native::shared_take_or_clone(other.resolver.unwrap()); + for (k, v) in other_resolver { + resolver.insert(k, crate::func::shared_take_or_clone(v)); + } + } + } + self } /// Filter out the functions, retaining only some based on a filter predicate. diff --git a/tests/modules.rs b/tests/modules.rs index 69e2ef82..d6bacf3f 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -282,6 +282,19 @@ fn test_module_resolver() -> Result<(), Box> { let result: INT = engine.call_fn(&mut Scope::new(), &ast, "foo", (2 as INT,))?; assert_eq!(result, 84); + + let mut ast2 = engine.compile("fn foo(x) { 42 }")?; + + let len = ast.resolver().unwrap().len(); + + ast2 += ast; + + assert!(ast2.resolver().is_some()); + assert_eq!(ast2.resolver().unwrap().len(), len); + + let result: INT = engine.call_fn(&mut Scope::new(), &ast2, "foo", (2 as INT,))?; + + assert_eq!(result, 84); } Ok(())