[IronPython] bug with closure in coroutine
Dino Viehland
dinov at microsoft.com
Wed Jan 27 19:08:42 CET 2010
It's so easy to fix it's actually already fixed for 2.6.1 :) Thanks for reporting it though.
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ronnie Maor
Sent: Wednesday, January 27, 2010 8:17 AM
To: Discussion of IronPython
Subject: [IronPython] bug with closure in coroutine
Hi IronPython team,
Seems IronPython 2.6 has some problems with compiling coroutines that contain closures:
tmp.py:
def coroutine():
x = yield 3
def inner():
print 'x=',x
inner()
c = coroutine()
c.next()
c.send(10)
with CPython:
C:\Temp>python tmp.py
x= 10
Traceback (most recent call last):
File "tmp.py", line 9, in <module>
c.send(10)
StopIteration
with IronPython 2.6:
C:\Temp>ipy tmp.py
Traceback (most recent call last):
File "tmp.py", line 7, in tmp.py
TypeError: Unable to cast object of type 'Microsoft.Scripting.Ast.FieldExpression' to type 'Microsoft.Scripting.Ast.BlockExpression'.
workarounds:
1) re-assign the result returned from yield to another variable
def coroutine():
tmp_x = yield 3
x = tmp_x
def inner():
print 'x=',x
inner()
2) pass the value explicitly instead of using a closure
def coroutine():
x = yield 3
def inner(x):
print 'x=',x
inner(x)
hope it's easy to fix
thanks
Ronnie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100127/55c2cf21/attachment.html>
More information about the Ironpython-users
mailing list