diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index e65b203..1f71ad5 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -717,8 +717,18 @@ namespace chaiscript { matching_func = begin; } else { - // More than one function matches, not attempting - throw exception::dispatch_error(plist, std::vector(orig, end)); + // handle const members vs non-const member, which is not really ambiguous + const auto &mat_fun_param_types = (*matching_func)->get_param_types(); + const auto &next_fun_param_types = (*begin)->get_param_types(); + + if (plist[0].is_const() && !mat_fun_param_types[1].is_const() && next_fun_param_types[1].is_const()) { + matching_func = begin; // keep the new one, the const/non-const matchup is correct + } else if (!plist[0].is_const() && !mat_fun_param_types[1].is_const() && next_fun_param_types[1].is_const()) { + // keep the old one, it has a better const/non-const matchup + } else { + // ambiguous function call + throw exception::dispatch_error(plist, std::vector(orig, end)); + } } } @@ -803,12 +813,6 @@ namespace chaiscript return (*(func.second))(plist, t_conversions); } } catch (const exception::bad_boxed_cast &) { - //std::cout << "Bad Boxed Cast: " << func.second->get_arity() << '('; - //for (const auto &p : plist) { - // std::cout << p.get_type_info().name() << ','; - //} - //std::cout << ")\n"; - //parameter failed to cast, try again } catch (const exception::arity_error &) { //invalid num params, try again diff --git a/unittests/vector_access.chai b/unittests/vector_access.chai index d9868d7..48ca8bd 100644 --- a/unittests/vector_access.chai +++ b/unittests/vector_access.chai @@ -2,7 +2,9 @@ auto x = [1, 2, 3] assert_equal(3, x[2]) -for (auto i = x.size() - 1; i >= 0; --i) +for (auto i = x.size()-1; i > 0; --i) { + print("Index: " + to_string(i)) print(x[i]); + x[i] = 23; }