[Mono-dev] Mono 2.8 regression
Tom Spink
tspink at gmail.com
Mon Dec 20 04:20:15 EST 2010
Hello,
There doesn't seem to be any relation between S and T - which means
the types are incompatible, and so not eligible for generic type
parameter variance.
The reason is, the abstract function definition specifies a type
constraint 'T' and even though your overridden method signature is
identical, it's using a different type constraint to the delegate
definition and so the cast is not valid.
So it looks like a bug in the Mono compiler was fixed - now you just
need to fix the bug in your code! You can make them compatible (and
hence eligible for variance) by specifying constraints, but in order
to specify a constraint on the override method, you need to propagate
that constraint to the abstract class.
-- Spink
On 20 December 2010 09:01, Federico Di Gregorio <fog at initd.org> wrote:
> Hi *,
>
> I guess it's my fault, not Mono's, but some code that compiled well on
> 2.6 doesn't work anymore on 2.8. I suppose this is somewhat related to
> covariance/contravariance of delegates but I'd like to have someone tell
> me «Eck! Whay did you do that? That's wrong!». Here is the error:
>
> test.cs(15,16): error CS0030: Cannot convert type
> `System.Func<string,int,T>' to `System.Func<string,int,S>'
>
> And here is the code:
>
> using System;
> using System.Collections.Generic;
>
> public abstract class A
> {
> public abstract Func<string,int,T> GetXXX<T>();
> }
>
> public class C<T> : A
> {
> Func<string,int,T> xxx;
>
> public override Func<string,int,S> GetXXX<S>()
> {
> return (Func<string,int,S>)xxx;
> }
> }
>
> --
> Federico Di Gregorio fog at initd.org
> To prepare such test data, I get into the meaniest, nastiest frame of
> mind that I can manage, and I write the cruelest code I can think of;
> then I turn around and I embed that in even nastier constructions
> that are almost obscene. -- D.E.Knuth
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
--
Tom Spink
More information about the Mono-devel-list
mailing list