Find, test and fix an issue related to function argument type reporting when discussing dynamic object functions (ie, def int::somefunc() {} )
This commit is contained in:
@@ -60,7 +60,7 @@ namespace chaiscript
|
||||
const std::string &t_type_name,
|
||||
const Proxy_Function &t_func,
|
||||
const boost::optional<Type_Info> &t_ti = boost::optional<Type_Info>())
|
||||
: Proxy_Function_Base(t_func->get_param_types()),
|
||||
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)),
|
||||
m_type_name(t_type_name), m_func(t_func), m_ti(t_ti)
|
||||
{
|
||||
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
|
||||
@@ -125,6 +125,22 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
private:
|
||||
static std::vector<Type_Info> build_param_types(
|
||||
const std::vector<Type_Info> &t_inner_types, boost::optional<Type_Info> t_objectti)
|
||||
{
|
||||
if (t_objectti)
|
||||
{
|
||||
std::vector<Type_Info> types(t_inner_types);
|
||||
|
||||
assert(types.size() > 1);
|
||||
assert(types[1].bare_equal(user_type<Boxed_Value>()));
|
||||
types[1] = *t_objectti;
|
||||
return types;
|
||||
} else {
|
||||
return t_inner_types;
|
||||
}
|
||||
}
|
||||
|
||||
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
|
||||
const boost::optional<Type_Info> &ti)
|
||||
{
|
||||
|
@@ -5,6 +5,10 @@ def test_function(a)
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// test_function tests
|
||||
assert_equal(test_function.get_arity(), 1);
|
||||
assert_equal(test_function.get_annotation(), "#Test Function Description\n");
|
||||
assert_equal(test_function.get_contained_functions().size(), 0);
|
||||
@@ -16,6 +20,24 @@ assert_not_equal(test_function, `+`);
|
||||
|
||||
assert_equal(test_function.call([1]), 1);
|
||||
|
||||
// dynamic object function tests
|
||||
|
||||
def int::test_fun()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
assert_equal(test_fun.get_arity(), 1);
|
||||
assert_equal(test_fun.get_contained_functions.size(), 1);
|
||||
assert_equal(test_fun.get_param_types().size(), 2);
|
||||
assert_equal(test_fun, test_fun);
|
||||
var test_fun_types = test_fun.get_param_types();
|
||||
assert_equal(true, test_fun_types[0].bare_equal(Object_type));
|
||||
assert_equal(true, test_fun_types[1].bare_equal(int_type));
|
||||
|
||||
|
||||
// built-ins tests
|
||||
|
||||
assert_equal(2, `==`.get_arity());
|
||||
|
||||
// < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string)
|
||||
|
Reference in New Issue
Block a user