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


shyouhei (Shyouhei Urabe) wrote:
> When you want to use it in while loop your supposition is not that concrete.

not clear what you're saying

> 
> 
>   while ! line = gets do
>      ....
>   end

your example merely illustrates the current behavior, it does not address its correctness

First of all, it doesn't matter where the expression appears, the rules of precedence don't vary (at least I would hope not), so there is no reason to introduce context into the discussion, is there?

The precedence rules are pretty clearly spelled out in "the ruby programming language" book, the ! operator has higher precedence than the = operator, therefore "!a = b" is "(!a) = b" not "!(a = b)"

 

----------------------------------------
Bug #9251: ! operator has lower precedence than = in an assignment expression
https://bugs.ruby-lang.org/issues/9251#change-43689

Author: rits (First Last)
Status: Open
Priority: Normal
Assignee: 
Category: 
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/