diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 2009923..acc9366 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -396,6 +396,7 @@ namespace detail { m->add(user_type(), type); typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &); + m->add(fun(static_cast(&MapType::operator[])), "[]"); container_type(type, m); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 95b99ea..0288b4b 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -411,22 +411,18 @@ namespace chaiscript */ Boxed_Value Inline_Map_AST_Node::eval(Dispatch_Engine &ss) { try { - Boxed_Value retval = ss.call_function("Map"); + std::map retval; for (size_t i = 0; i < this->children[0]->children.size(); ++i) { try { - Boxed_Value slot - = ss.call_function("[]", retval, this->children[0]->children[i]->children[0]->eval(ss)); - ss.call_function("=", slot, this->children[0]->children[i]->children[1]->eval(ss)); - } - catch (const dispatch_error &) { - throw Eval_Error("Can not find appropriate '=' for map init"); + retval[boxed_cast(this->children[0]->children[i]->children[0]->eval(ss))] + = ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(ss)); } catch(Eval_Error &ee) { ee.call_stack.push_back(this->children[0]->children[i]); throw; } } - return retval; + return const_var(retval); } catch (const dispatch_error &) { throw Eval_Error("Can not find appropriate 'Map()'"); diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai new file mode 100644 index 0000000..d267bcf --- /dev/null +++ b/unittests/malformed_inline_map.chai @@ -0,0 +1,2 @@ + +assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } );