diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 1126f28e..6a95127f 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -43,20 +43,6 @@ namespace chaiscript namespace detail { - struct Dynamic_Object_Attribute - { - static Boxed_Value func(const std::string &t_type_name, const std::string &t_attr_name, - Dynamic_Object &t_do) - { - if (t_do.get_type_name() != t_type_name) - { - throw exception::bad_boxed_cast("Dynamic object type mismatch"); - } - - return t_do.get_attr(t_attr_name); - } - }; - /** * A Proxy_Function implementation designed for calling a function * that is automatically guarded based on the first param based on the diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 684a29fb..1bb296db 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1182,8 +1182,16 @@ namespace chaiscript virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ try { - t_ss.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, - this->children[1]->text, std::placeholders::_1))), this->children[1]->text); + + t_ss.add(Proxy_Function + (new dispatch::detail::Dynamic_Object_Function( + this->children[0]->text, + fun(std::function(std::bind(&dispatch::Dynamic_Object::get_attr, + std::placeholders::_1, + this->children[1]->text + ))) + ) + ), this->children[1]->text); } catch (const exception::reserved_word_error &) { diff --git a/unittests/object_attr_same_name.chai b/unittests/object_attr_same_name.chai new file mode 100644 index 00000000..fa20bac4 --- /dev/null +++ b/unittests/object_attr_same_name.chai @@ -0,0 +1,9 @@ +attr bob::z +def bob::bob() { this.z = 10 } + +attr bob2::z +def bob2::bob2() { this.z = 12 } + +var b = bob(); +var b2 = bob2(); +