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

Key: BOO-88
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Rodrigo B. de Oliveira
Reporter: ian Maclean
Votes: 1
Watchers: 0
Operations

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

can't currently create a callable reference with constructor syntax

Created: 11/Aug/04 12:42 AM   Updated: 25/Nov/05 11:42 AM
Component/s: Compiler
Affects Version/s: 0.5.6
Fix Version/s: 0.7.6

Time Tracking:
Not Specified

Issue Links:
dependent
 


 Description  « Hide
when creating callable/delegate instances the constructor syntax gives a compile error. So the following works ok :

callable OutputHandler(message as string) # this baby is a delegate
def printTest(message as string):
System.Console.WriteLine(message)

handler as OutputHandler
handler = printTest

but :
handler = OutputHandler(printTest)

gives the following compile error:
BCE0024: The type 'OutputHandler' does not have a visible constructor that matches the argument list '(callable(System.String) as System.Void)'.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
ian Maclean - 11/Aug/04 12:50 AM
looking at the generated il for the working version :
L_0000: ldnull
L_0001: ldftn void DelegateTestModule::printTest(string)
L_0007: newobj instance void OutputHandler::.ctor(object, native int)
L_000c: stloc.0
L_000d: ret

OutputHandler's constructor is being called. So it would make sense that an explicit call to the constructor should also work.


Rodrigo B. de Oliveira - 11/Aug/04 01:29 AM
The explicit constructor call does work but it is a little more verbose:

<snip>
callable Function()

def click():
print("click")

c = Function(null, _addressof_(click))
c()
</snip>

Notice that explicit delegate constructor calls like the one above are not type checked (meaning that the compiler will not complain if the method reference is not compatible with the delegate type).

But does this solve the issue?


ian Maclean - 11/Aug/04 02:18 AM
That works - thanks. However now I've run into another related issue:
with the following code:

def clicked(sender, args as System.EventArgs):
print("clicked!")

clickedHandler = System.EventHandler(null, _addressof_(clicked))
c = Clickable()

c.Click += clicked # this works
c.Click += clickedHandler # this gives compile error

an explicitly created delegate handle fails on assignment with:
BCE0032: The event 'BooCompiler.Tests.Clickable.Click' expects a callable reference compatible with 'System.EventHandler'.

looking at the IL for the working assignment:
L_0008: ldftn void My-delegatesModule::clicked(object, [mscorlib]System.EventArgs)
L_000e: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int)
L_0013: call instance void [SupportingClasses]BooCompiler.Tests.Clickable::add_Click([mscorlib]System.EventHandler)

It is contructing an EventHandler object but doing the same in boo code give a failure.


Rodrigo B. de Oliveira - 11/Aug/04 03:29 AM
fixed in the repository.

ian Maclean - 11/Aug/04 04:34 AM
fantasitc ! - Thanks for the quick turnaround.

Daniel Grunwald - 16/Aug/05 04:26 AM
I'm still having this problem:

def Method(sender as object, e as EventArgs):
print "!!"

h = EventHandler(Method)

BCE0024: The type 'System.EventHandler' does not have a visible constructor that matches the argument list '(callable(System.Object, System.EventArgs) as System.Void)'.

This problem currently requires an ugly hack in the C# parser (involving .EndsWith("EventHandler")...)