Issue #9251 has been updated by rits (First Last).


mame (Yusuke Endoh) wrote:
> I think you are confused because you know lvalue.  In C, lvalue is indeed an expression.  But in Ruby, "lhs" (not lvalue) is NOT an expression.  This is a matter of taste of the language design.
> 
> As the thought, the book may be slightly unkind if it lists "=" in the precedence table without notes.  (Again, I don't have the book.)
> 
> Anyway, the current behavior is useful and actually used for some people.  It must not change to an inconvenient behavior just because of a philosophical reason.
> 
> -- 
> Yusuke Endoh <mame / tsg.ne.jp>

Note that I have not asserted that lfs is or should be an expression, so your focus on this is a straw man, the issue is whether it's necessary or desirable to have different precedence rules for the lfs of = than for rhs.

I submit it is neither necessary nor desirable.  a * -b = -c / d should mean (a * -b) = (-c / d) per the spec, and produce an error. That's the path of logic, clarity, simplicity and least surprise. For it to mean a * -(b = (-c / d)) is beyond useless, it's dangerous, will conceal bugs.
----------------------------------------
Bug #9251: ! operator has lower precedence than = in an assignment expression
https://bugs.ruby-lang.org/issues/9251#change-43715

Author: rits (First Last)
Status: Feedback
Priority: Low
Assignee: 
Category: doc
Target version: 
ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


irb(main):001:0> !a = 1
(irb):1: warning: found = in conditional, should be ==
=> false
irb(main):002:0> a
=> 1

! is supposed to have higher precedence than =, so !a = 1 should be (!a) = 1, and thus an error, not !(a = 1) 



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