diff --git a/src/engine.rs b/src/engine.rs index cb56c28b..24a1b20b 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1347,7 +1347,11 @@ impl Engine { // Normal assignment ScopeEntryType::Normal if op.is_empty() => { if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() { - *lhs_ptr.write_lock::().unwrap() = rhs_val; + *lhs_ptr.write_lock::().unwrap() = if rhs_val.is_shared() { + rhs_val.clone_inner_data().unwrap() + } else { + rhs_val + }; } else { *lhs_ptr = rhs_val; } @@ -1368,19 +1372,16 @@ impl Engine { .get_fn(hash_fn, false) .or_else(|| self.packages.get_fn(hash_fn, false)) { - #[cfg(not(feature = "no_shared"))] - let mut lock_guard; + if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() { + let mut lock_guard = lhs_ptr.write_lock::().unwrap(); + let lhs_ptr_inner = lock_guard.deref_mut(); - #[cfg(not(feature = "no_shared"))] - let lhs_ptr = if lhs_ptr.is_shared() { - lock_guard = Some(lhs_ptr.write_lock::().unwrap()); - lock_guard.as_deref_mut().unwrap() + // Overriding exact implementation + func(self, lib, &mut [lhs_ptr_inner, &mut rhs_val])?; } else { - lhs_ptr - }; - - // Overriding exact implementation - func(self, lib, &mut [lhs_ptr, &mut rhs_val])?; + // Overriding exact implementation + func(self, lib, &mut [lhs_ptr, &mut rhs_val])?; + } } else if run_builtin_op_assignment(op, lhs_ptr, &rhs_val)?.is_none() { // Not built in, map to `var = var op rhs` let op = &op[..op.len() - 1]; // extract operator without = @@ -1396,7 +1397,11 @@ impl Engine { .map_err(|err| err.new_position(*op_pos))?; if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() { - *lhs_ptr.write_lock::().unwrap() = value; + *lhs_ptr.write_lock::().unwrap() = if value.is_shared() { + value.clone_inner_data().unwrap() + } else { + value + }; } else { *lhs_ptr = value; }