cy99 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

Unpacking is translated into C++ code incorrectly #159

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
1. The issue can be reproduced using the following sample code ("unpack2.py" 
file is attached):

====================
def unpack2(lst):
  try:
    c1, c2 = lst
    print c1
  except ValueError:
    print lst

unpack2([1, 2, 3])
====================

2. Run "python unpack2.py"

$ python unpack2.py 
[1, 2, 3]

3. Translate "unpack2.py" using shedskin and run the resulted program:

$ shedskin unpack2.py 
...
$ make
...
$ ./unpack2 
1

Thereby, the resulted C++ code is incorrect. The problem is in translation of 
unpacking statements. E.g. "c1, c2 = list" is translated into the following 
snippet:

===========================
c1 = __0->__getfast__(0);
c2 = __0->__getfast__(1);
===========================

Whereas, the correct code would be something like that:

===========================
if (__0->__len__() != 2)
    throw new ValueError();
c1 = __0->__getfast__(0);
c2 = __0->__getfast__(1);
===========================

I'm using shedskin 0.9 and suspect that the issue is still reproducible for the 
GIT version.

Original issue reported on code.google.com by igor.bro...@gmail.com on 23 Oct 2011 at 8:10

Attachments:

GoogleCodeExporter commented 8 years ago
thanks a lot for reporting! ;) it's much appreciated. I will have a look at 
this for the next release.

Original comment by mark.duf...@gmail.com on 28 Oct 2011 at 1:56

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 6 Nov 2011 at 7:23

GoogleCodeExporter commented 8 years ago
hm, I'm not sure if support for this was recently added to python 2.x, but the 
following also does not seem to work with shedskin at the moment:

a, b = set([1,2])
a, b = {1: 4, 5: 7}
a, b = iter(set([1, 2]))

so yeah, this unpacking stuff could certainly use an update.. :-)

Original comment by mark.duf...@gmail.com on 8 Nov 2011 at 11:35

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 23 Nov 2011 at 1:42

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 11 Jan 2012 at 5:57