History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-677
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Rodrigo B. de Oliveira
Reporter: Chris Prinos
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

variable argument lists prevent callables from being invoked via dictionaries

Created: 28/Feb/06 07:53 PM   Updated: 11/Jun/07 04:56 PM
Component/s: Runtime (Boo.Lang)
Affects Version/s: 0.7.5
Fix Version/s: 0.7.8

Time Tracking:
Not Specified

Environment: win32 .NET 1.1, mono 1.1


 Description  « Hide
I have a dispatch mechanism which stores references to functions in a dictionary, and then calls the appropriate function by dictionary key. It works ok for functions with no parameters or a fixed number of parameters. For functions with variable arguement lists, I get the following exeption:

Unhandled Exception: System.InvalidCastException: Cannot cast from source type to destination type.
in <0x0004c> CompilerGenerated.___callable2:Call (System.Object[] args)
in <0x00120> Boo.Lang.Runtime.RuntimeServices:InvokeCallable (System.Object target, System.Object[] args)
in <0x002ac> TestModule:Main (System.String[] argv)

Note, code below is compiled with -ducky

"""
func1
func2 with arg: test
func3 param:multiple
func3 param:params
func1
func2 with arg: dispatcher arg test
func3 param:dispatcher
func3 param:multiple
func3 param:args
"""
def func1():
print 'func1'

def func2(arg1):
print 'func2 with arg: ' + arg1

def func3(*args):
for item in args:
print 'func3 param:' + item

func1()
func2('test')
func3('multiple', 'params')

dispatcher = {'f1': func1, 'f2': func2, 'f3': func3 }

dispatcher['f1']()
dispatcher['f2']('dispatcher arg test')
dispatcher['f3']('dispatcher', 'multiple', 'args')



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Doug H - 28/Feb/06 11:09 PM
Until this is fixed I would recommend using Invoke:

dispatcher['f1'].Invoke()
dispatcher['f2'].Invoke('dispatcher arg test')
dispatcher['f3'].Invoke('dispatcher', 'multiple', 'args')

Another thing that works is wrapping the args in an array:
dispatcher['f3'](('dispatcher', 'multiple', 'args'))
But that only works for that one case.


Rodrigo B. de Oliveira - 11/Jun/07 04:56 PM
Fixed in the repository. Thanks for the report!