ChaiScript/unittests/return_assignment.chai
leftibot 0d1ceed05d
Fix #473: Allow assignment expressions in return statements (#665)
The Return() parser function called Operator() to parse the return value,
which only handles arithmetic/logical operators but not assignments. Changed
it to call Equation(), which wraps Operator() and adds assignment parsing.
This is consistent with how If, For, and function argument parsing already
work. Enables `return foo = 5`, `return x += 1`, etc.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 17:13:50 -06:00

17 lines
319 B
ChaiScript

// 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())