[Mono-dev] PATCH: mcs: better type matching for anonymous methods

Casey Marshall cmarshall at pacificbiosciences.com
Thu Jan 31 19:58:24 EST 2008

Hi. The attached patch to mcs seems to fix bug 357047 (which I also
filed). The issue is that the compiler can't tell that:

  enumerable.Average(o => op on o that returns a double);


  enumerable.Average(delegate(T o) { return (op on o that returns a
double); });

Means Average<T>(IEnumerable<T>,Func<T,double>) or
Average<T>(IEnumerable<T>,Func<T,double?>). This means that you get an
error that the method call is ambiguous.

The patch works by inferring the return type of the argument, then
testing if that return value is an exact match for the return value of
the Func parameter. If so, it breaks ties with the exact match.

This is the first hacking I've done on mcs, so I'm not sure about how
correct this is. Comments are welcome.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080131/a2d93b30/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PR-357047.patch
Type: text/x-patch
Size: 1286 bytes
Desc: PR-357047.patch
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080131/a2d93b30/attachment.bin 

More information about the Mono-devel-list mailing list