AeroEng43 / shedskin

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

Use of print in function which can take two types silently produces incorrect code. #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I ran shedskin SVN HEAD on the following 4 line test program, and compiled
the resulting program:

def p(msg):
    print msg
p(15)
p("hello")

The output from shedskin was as follows (and appears reasonable, as far as
I know):

*** SHED SKIN Python-to-C++ Compiler 0.0.27 ***
Copyright 2005-2008 Mark Dufour; License GNU GPL version 3 (See LICENSE)
(Please send bug reports here: mark.dufour@gmail.com)

[iterative type analysis..]
**
iterations: 2 templates: 29
template <class A> p
[generating c++ code..]

The output I expected from running the resulting "foo" program was:
15
hello

However, the actual output was:
15
134762048

I half expected shedskin to complain that this program was passing two
different types to the p() function - however, it appears to attempt to
handle this by making p into a template.  Sadly, the attempt fails because
the code produced for the print assumes that the parameter is always an
integer.

I suppose that shedskin could reasonably report an error in this case, but
it would be lovely if it could handle it correctly.  Whichever - the
current behaviour of silently producing incorrect code seems like a bug.

Original issue reported on code.google.com by boulton.rj@gmail.com on 24 Feb 2008 at 1:47

GoogleCodeExporter commented 8 years ago
thanks for the report! yes, this is a bug, albeit not one that has high 
priority at
the moment. the problem, however, is not the dynamic argument to p(), because 
it is
not really dynamic but generic (as in C++). the problem is that I wrote print 
support
without considering a generic context. I can fix this, but probably won't get 
around
to it anytime soon.. note that the following works, where the print statement is
outside the generic function:

def p(msg):
    return msg
print p(15)
print p("hello")

Original comment by mark.duf...@gmail.com on 25 Feb 2008 at 2:31

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 25 Feb 2008 at 2:32

GoogleCodeExporter commented 8 years ago
as part of string-formatting/printing improvements, I made print() generate its 
own
format string.. which means this code now works :-)

thanks again for reporting!

Original comment by mark.duf...@gmail.com on 7 Nov 2008 at 2:57