Details
Description
I took an initial stab at fixing this in the boo.g grammar but was getting conflicts between "not" and "not in".
Sample code:
a = false
list = ["an item"]
print "list =", list
//I expected the below test to succeed when the list is empty,
//and fail when the list has an item.
//Instead it succeeds either way.
if not a and len(list) == 0:
print "INCORRECT SUCCESS?: not a and b"
else:
print "CORRECTLY FAILED: not a and b"
//i expected the above to be like this:
if (not a) and (len(list) == 0):
print "(not a) and b"
else:
print "CORRECTLY FAILED: (not a) and b"
//actually it is like this: (ran it through BooPrinterVisitor)
if (not (a and (len(list) == 0))):
print 'CORRECT SUCCESS: not (a and (b))'
else:
print 'FAILED: not (a and (b))'
I tested the code with python and C# (see below) and it gave a correct failure.
//python
a = False
l = ["an item"]
if not a and len(l) == 0:
print "incorrect success"
else:
print "correct failure"
//This C# test gives a correct failure:
using System;
using System.Collections;
namespace csharptest
{
class MainClass
{
public static void Main(string[] args)
{
bool a = false;
ArrayList list = new ArrayList();
list.Add("an item");
if (! a && list.Count == 0)
else
{ Console.WriteLine("correct failure: ! a && list.Count == 0"); } }
}
}
And another sample by Arron Washington:
Here's another test-case indicating that anything pass the "not"
expression is not evaluated by the compiler.
test =
{ print "Entered"; return false}if not false and test():
print "We mistakenly arrived at this conclusion!"
prints,
"We mistakenly arrived at this conclusion!"
when it should really print,
"Entered"
"We mistakenly arrived at this conclusion!"
patch applied. thanks Doug!