Issue #7170 has been reported by hasari (Hiro Asari).

----------------------------------------
Bug #7170: tOP_ASGN and rescue_modifier precedence, with a few confusing examples
https://bugs.ruby-lang.org/issues/7170

Author: hasari (Hiro Asari)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0dev (2012-10-12 trunk 37163) [x86_64-darwin12.2.0] 


parse.y shows that tOP_ASGN has precedence over modifier_rescue.

So I expect that

    a = 1
    a += [] rescue 5

should be parsed as "(a += []) rescue 5". Furthermore, it should evaluate to 5, and leave a untouched.

But in reality, this raises a TypeError. (If you rescue this TypeError, you can see that a is untouched.)

Likewise,

    a = 'a'
    a += b rescue 'c'

should not raise a NameError (for b), evaluate to 'c', and leave 'a' untouched.

However, in reality, this does not raise any exception, but it evaluates to 'ac' and assigns the value 'ac' to a.

Did I reason this incorrectly? Or is there a bug somewhere?


-- 
http://bugs.ruby-lang.org/