No implicit conversion due to several general restrictions
Building a piece of C # code using generics I created code that looks like this:
public class Test<U,V,W>
where U : V
where V : W
{
public W Cast(U argument)
{
return argument;
}
}
The string return
cannot compile (in mono 3.2.8.0: "Cannot implicitly convert the type of U to W") although it seems clear that U must be a subclass of W (technically there can be value types but the above fails even if all three common parameters are limited reference types). If U
limited directly from W
, everything works fine.
The above code is trivial to fix (just insert the cast into V, which, of course, will always be successful). I have two questions, most importantly, why is the code failing to compile? Links to the relevant C # spec snippets (if any) would be most welcome! Second, would the (seemingly redundant) conversion to V
introduce (useless) runtime type checking?
source to share
My guess is that Monod doesn't understand that if U: V and V: W then U: W. Try to set this limit as well?
edit: I see you mentioned this in your answer (I missed it). Since this is the case, I would say it is a bug in Mono. Just put a limit and do with it? Perhaps please report a bug.
source to share