www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - parser bug?

reply Charles Hixson via Digitalmars-d-learn writes:
The code:
     void    go    (ulong    recNum)
     {    assert (buf[0] == (fh.sizeof + recNo * buf.length) & 0x7f);
         if    (dirty)
yields the error message:
ells$ dmd test.d
test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length must be 
parenthesized when next to operator &

And I'll swear it looks parenthesized to me.

     void    go    (ulong    recNum)
     {    ubyte    tst    =    (fh.sizeof + recNo * buf.length) & 0x7f;
         assert (buf[0] == tst);
         if    (dirty)

compiles without error.

Any idea what's going on?
Oct 23 2014
parent "anonymous" <anonymous example.com> writes:
On Thursday, 23 October 2014 at 18:15:26 UTC, Charles Hixson via
Digitalmars-d-learn wrote:
 The code:
     void    go    (ulong    recNum)
     {    assert (buf[0] == (fh.sizeof + recNo * buf.length) & 
 0x7f);
         if    (dirty)
 yields the error message:
 ells$ dmd test.d
 test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length 
 must be parenthesized when next to operator &

 And I'll swear it looks parenthesized to me.
The expression is of the form `a == b & c`. You must parenthesize either `a == b` or `b & c`, making it `(a == b) & c` or `a == (b & c)`.
Oct 23 2014