lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Linker: Your third case "1 or false and true or false" is not a bug.  Due to operator precedence it is equivalent to "1 or (false and true) or false".

I can generalize the problem a bit, though.  For any X, Y, Z, where X ~=nil and X~=false:

    ((X or Y) and true) or Z  -->  X   (should always be true)
    (X or Y) and (true or Z)  -->  X   (should always be true)

Extra parentheses are for clarity and do not affect the results.

-bhk

________________________________________
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Linker
Sent: Wednesday, April 15, 2009 11:47 PM
To: Lua list
Subject: Re: code generation bug

I had try it in Lua 5.1.4 win xp:

> =1 or false
1 -- right
> =1 and true or false
true -- right
> =1 or false and true or false
1 -- wrong
> =((1 or false) and true)or false
1 -- wrong
>


On Thu, Apr 16, 2009 at 12:37, Kelley, Brian <bkelley@qualcomm.com> wrote:
I was surprised to notice the following:

  Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
  > =((1 or false) and true) or false
  1

Same results on 5.1.2 and 5.1.3, MacOS and Windows.

For what it's worth, I observed in lcode.c that the OPR_AND expression inherited the 'k' (kind) of VTRUE from its rhs subexpression, which seems wrong and seems to throw off the subsequent call to luaK_goiffalse().

-bhk



-- 
Regards,
Linker Lin
linker.m.lin@gmail.com