From 538af8caeef551616200eec35082cd5416e1cd1d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 26 Jan 2022 22:15:19 +0800 Subject: [PATCH] Scope::clone_visible clones value access mode also. --- CHANGELOG.md | 5 +++++ src/types/scope.rs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 112423ad..068a83de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Rhai Release Notes Version 1.5.0 ============= +Bug fixes +--------- + +* In `Scope::clone_visible`, constants are now properly cloned as constants. + New features ------------ diff --git a/src/types/scope.rs b/src/types/scope.rs index 56f21748..e6b0de89 100644 --- a/src/types/scope.rs +++ b/src/types/scope.rs @@ -534,8 +534,12 @@ impl Scope<'_> { Self::new(), |mut entries, (index, (name, alias))| { if !entries.names.iter().any(|(key, _)| key == name) { + let orig_value = &self.values[len - 1 - index]; + let mut value = orig_value.clone(); + value.set_access_mode(orig_value.access_mode()); + entries.names.push((name.clone(), alias.clone())); - entries.values.push(self.values[len - 1 - index].clone()); + entries.values.push(value); } entries },