diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb30e7c..462bc2ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Bug fixes * Self-contained `AST` now works properly with `Engine::call_fn`. * Missing `to_int` from `Decimal` is added. * Parsing of index expressions is relaxed and many cases no longer result in an index-type error to allow for custom indexers. +* Merging a self-contained `AST` into another `AST` now works properly. Deprecated API's ---------------- diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 10484cf6..08099edf 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -506,7 +506,7 @@ impl AST { lib }; - if !other.source.is_empty() { + let mut _ast = if !other.source.is_empty() { Self::new_with_source( merged, #[cfg(not(feature = "no_function"))] @@ -519,7 +519,31 @@ impl AST { #[cfg(not(feature = "no_function"))] lib, ) + }; + + #[cfg(not(feature = "no_module"))] + match ( + self.resolver().map_or(0, |r| r.len()), + other.resolver().map_or(0, |r| r.len()), + ) { + (0, 0) => (), + (_, 0) => { + _ast.set_resolver(self.resolver().unwrap().clone()); + } + (0, _) => { + _ast.set_resolver(other.resolver().unwrap().clone()); + } + (_, _) => { + let mut resolver = (**self.resolver().unwrap()).clone(); + let other_resolver = (**other.resolver().unwrap()).clone(); + for (k, v) in other_resolver { + resolver.insert(k, crate::func::shared_take_or_clone(v)); + } + _ast.set_resolver(resolver); + } } + + _ast } /// Combine one [`AST`] with another. The second [`AST`] is consumed. ///