hg2051 / shedskin

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

Calling pointer to functions work. Calling a pointers to class constructor generates bad C++ #190

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. try to compile this with shedskin:

class MyClass():
    def __init__(self, str):
        self.str = str

    def printhi(self):
        print("hi " + self.str)

funcptr = MyClass

c = funcptr("alpha")
c.printhi()

What is the expected output? What do you see instead?

This generates C++ code that does not compile.

If I do this it works (wrapping the call the constructor in a function)

class MyClass():
    def __init__(self, str):
        self.str = str 

    def printhi(self):
        print("hi " + self.str)

def mkMyClass(str):
    return MyClass(str)

funcptr = mkMyClass

c = funcptr("alpha")
c.printhi()

What version of the product are you using? On what operating system?

shedskin-mainline

Please provide any additional information below.

Original issue reported on code.google.com by paulhaeb...@gmail.com on 3 May 2013 at 2:52

Attachments:

GoogleCodeExporter commented 9 years ago
thanks!

I added a mention in the 'python subset restrictions' for now that classes 
cannot be 'passed around'. I don't think this limitation will be lifted in the 
near future.. 

we could (and perhaps we do) support passing them around, as long as nothing 
other than accessing __name__ happens, but that's not very useful.

Original comment by mark.duf...@gmail.com on 5 May 2013 at 1:02