[Mono-dev] Generic Constraints Regression in 2.8

dan witt dan.witt at gmail.com
Mon Nov 15 00:39:12 EST 2010


Except that Y is constrained to be of type Z and so is guaranteed to be
a reference type.

On Mon, Nov 15, 2010 at 12:30 AM, Bojan Rajkovic <severedcross at gmail.com>wrote:

> On Nov 14, 2010, at 10:16 PM, Tom Philpot wrote:
>
> The following code compiled with a warning on Mono 2.7 (as of 147679)  but
> has  an error in 2.8.
>
> namespace Application
> {
> public class Z {}
>
> public class A<X, Y>
> where Y : Z
> where X : Y
> {
> protected void SomeOperation(Y y)
> {
> X x = y as X;
> }
> }
>
> public class Foo { public static void Main() {} }
> }
>
> /opt/mono-2.8/bin/gmcs CS0413Regression.cs
> CS0413Regression.cs(12,33): error CS0413: The `as' operator cannot be used
> with a non-reference type parameter `X'. Consider adding `class' or a
> reference type constraint
> Compilation failed: 1 error(s), 0 warnings
>
> /opt/mono-r147679/bin/gmcs CS0413Regression.cs
> CS0413Regression.cs(12,27): warning CS0219: The variable `x' is assigned
> but its value is never used
> Compilation succeeded - 1 warning(s)
>
>
> The error message here is the correct thing to do—as casts are only valid
> with reference types, because they can result in null, which is invalid for
> a value type. If this raised only a warning in gmcs earlier, it was a bug.
>
> —Bojan
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20101115/e7de0ef7/attachment.html 


More information about the Mono-devel-list mailing list