diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index edfc0e06..be2a7525 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -2282,7 +2282,7 @@ namespace chaiscript { const auto prev_stack_top = m_match_stack.size(); if (Keyword("return")) { - Operator(); + Equation(); build_match>(prev_stack_top); return true; } else { diff --git a/unittests/return_assignment.chai b/unittests/return_assignment.chai new file mode 100644 index 00000000..02a008d4 --- /dev/null +++ b/unittests/return_assignment.chai @@ -0,0 +1,16 @@ +// Test that assignment expressions work inside return statements +// Issue #473: `return foo = 5` should work + +def return_assign() { + var x = 0 + return x = 5 +} + +assert_equal(5, return_assign()) + +def return_member_assign() { + var o = Dynamic_Object() + return o.value = 42 +} + +assert_equal(42, return_member_assign())