CityOfZion / neo-boa

Python compiler for the Neo2 Virtual Machine, see neo3-boa for NEO3
MIT License
69 stars 55 forks source link

`is not None` problems #32

Open shargon opened 6 years ago

shargon commented 6 years ago

This source produce if (false) output

def Main(operation):

    if operation is not None:
        return True
    else:
        return False

As you can see, is impossible to return true in this opCode output

image

Could you check it @localhuman ?

belane commented 6 years ago

if operation: could be the right python style to do it. But you can do (and it should work):

>>> def Test(argument):
      if argument is not None:
              return True
      else:
              return False

>>> Test(1)
True
>>> Test(None)
False

in this case I think the appropriate would be

def Main(operation=None):
    if operation:
        return True
    else:
        return False

avm for this last example is well compiled: avm

brianlenz commented 6 years ago

This code originated from the NEX neo-ico-template:

https://github.com/neonexchange/neo-ico-template/blob/master/ico_template.py#L61

I would think these three should be functionally identical:

if operation: if operation != None: if operation is not None:

or am I missing something?

belane commented 6 years ago

Test 1 👍

def Main(operation):
    if operation:
        return True
    else:
        return False

image

Test 2 👍

def Main(operation):
    if operation != None:
        return True
    else:
        return False

image

Test 3 👎

def Main(operation):
    if operation is not None:
        return True
    else:
        return False

image

localhuman commented 6 years ago

With new version of compiler I will be interested in this!

I'll have to add a NoneTest to see and document exactly how it behaves.