Yes, the OP's code was definitely wrong. But I am intensely puzzled as to how it worked ? I just tried it, and, again, it works.
In function A, the result.bar contains 'foo', at the start of the function, the only way it can get that information is from functions B's result.bar. Just looking at the code, I would have said function A's result.bar is just as likely to contain the Complete Works of Shakespeare as "foo".
Until the assignment happens at the end of function A, there is no connection between the two result variables. Is there ?
Davo
EDIT: No, I see, a function uses the variable its going to write to as its result variable. Wow, I did not realise that .....