cy99 / shedskin

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

casting of empty dicts/lists/etc. #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a non-empty dictionary
2. Create a second dictionary, inserting the first dictionary as an item
3. Insert an empty dictionary into the first

What is the expected output? What do you see instead?
I would expect either 1) it to compile fine, or 2) Shedskin to fail and
explain that dicts in dicts are unsupported.
Instead, Shedskin outputs c++ code with no complaint, but g++ fails to
compile it.

What version of the product are you using? On what operating system?
Shedskin 3.1, G++ 4.4

Please provide any additional information below.
I have attached the relevant code below.

Hello from Reddit! And I have to say, your compiler is quite cool!

Original issue reported on code.google.com by wackywen...@gmail.com on 13 Jan 2010 at 9:11

Attachments:

GoogleCodeExporter commented 8 years ago
thanks for reporting! this should work without any problem.. but unfortunately, 
it
looks like shedskin forgets to add a cast here, so the C++ compiler doesn't 
like it.
I will see if I can fix this in SVN. this is an ugly workaround in any case:

def emptydict():
    return {}
    return {1:1}

d2[2] = emptydict()

Original comment by mark.duf...@gmail.com on 14 Jan 2010 at 8:42

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 14 Jan 2010 at 8:43

GoogleCodeExporter commented 8 years ago
to anyone who would like to help, it would be useful to find similar cases that 
fail,
also for other types than dicts.

Original comment by mark.duf...@gmail.com on 14 Jan 2010 at 8:44

GoogleCodeExporter commented 8 years ago
btw, note that the problem is not from using dicts in dicts (still a static 
type:
dict(int -> dict(int, int))), but using an empty dict in a way such that 
shedskin
forgets to add a cast.. ^^

Original comment by mark.duf...@gmail.com on 14 Jan 2010 at 8:48

GoogleCodeExporter commented 8 years ago
Your comment gave me something to think about, so I tried with lists... and I 
found
another set of code that fails:
definiteinnerlist=[1]
outerlist=[]
emptyinnerlist=[]
outerlist.append(definiteinnerlist)
outerlist.append(emptyinnerlist)

The compiler seems to not to find the right cast for a collection, if the only
indication of that collection's type is that it is added to another collection
alongside other members with more definite types.

Original comment by wackywen...@gmail.com on 14 Jan 2010 at 1:01

GoogleCodeExporter commented 8 years ago
Another bypassing solution:

d={1:1}
del d[1]

or fancier, but one line:
d={} and {1:1}

The empty dict (or list) is False, so the 'and' is short-circuited and the 
empty-list
is returned, and d is set to the empty list.

Original comment by wackywen...@gmail.com on 14 Jan 2010 at 1:18

GoogleCodeExporter commented 8 years ago
thanks! I will add both tests to the test set, and try to fix the underlying 
problem
one of these days. I have to rest a bit first after releasing 0.3.. :-) 

Original comment by mark.duf...@gmail.com on 14 Jan 2010 at 1:35

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 19 Jan 2010 at 8:04

GoogleCodeExporter commented 8 years ago
alright, these code fragments now work in SVN. fortunately, the problem was 
easier to
solve than I expected. I will close the issue after generalizing the solution a 
bit.
thanks again for reporting!

Original comment by mark.duf...@gmail.com on 17 Mar 2010 at 12:11

GoogleCodeExporter commented 8 years ago
I consider this fixed for now. there are a few wacky cases left, but we'll deal 
with
them when they turn up.

Original comment by mark.duf...@gmail.com on 21 Mar 2010 at 9:45