From b0ab6e95f514e56b17ebf2a6f0e176a30dd5e458 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 4 Aug 2020 18:38:33 +0800 Subject: [PATCH] Fix currying in map closure calls. --- src/fn_call.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index d56487e2..c7d9050c 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -705,12 +705,25 @@ impl Engine { #[cfg(not(feature = "no_object"))] if let Some(map) = obj.read_lock::() { if let Some(val) = map.get(_fn_name) { - if let Some(f) = val.read_lock::() { + if let Some(fn_ptr) = val.read_lock::() { // Remap the function name - redirected = f.get_fn_name().clone(); + redirected = fn_ptr.get_fn_name().clone(); _fn_name = &redirected; - // Recalculate the hash based on the new function name - _hash = calc_fn_hash(empty(), _fn_name, idx.len(), empty()); + // Add curried arguments + if !fn_ptr.curry().is_empty() { + fn_ptr + .curry() + .iter() + .cloned() + .enumerate() + .for_each(|(i, v)| idx.insert(i, v)); + } + // Recalculate the hash based on the new function name and new arguments + _hash = if native { + 0 + } else { + calc_fn_hash(empty(), _fn_name, idx.len(), empty()) + }; } } };