Fixes array access with arithmetic conversions

Closes #156
This commit is contained in:
Jason Turner
2015-04-06 07:21:32 -06:00
parent 9422bc7b2d
commit 1557dabf4f
2 changed files with 15 additions and 9 deletions

View File

@@ -717,8 +717,18 @@ namespace chaiscript
{ {
matching_func = begin; matching_func = begin;
} else { } else {
// More than one function matches, not attempting // handle const members vs non-const member, which is not really ambiguous
throw exception::dispatch_error(plist, std::vector<Const_Proxy_Function>(orig, end)); 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<Const_Proxy_Function>(orig, end));
}
} }
} }
@@ -803,12 +813,6 @@ namespace chaiscript
return (*(func.second))(plist, t_conversions); return (*(func.second))(plist, t_conversions);
} }
} catch (const exception::bad_boxed_cast &) { } 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 //parameter failed to cast, try again
} catch (const exception::arity_error &) { } catch (const exception::arity_error &) {
//invalid num params, try again //invalid num params, try again

View File

@@ -2,7 +2,9 @@ auto x = [1, 2, 3]
assert_equal(3, x[2]) 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]); print(x[i]);
x[i] = 23;
} }