[Mono-bugs] [Bug 75668][Wis] New - GMCS Incorrect 'as' Operator Behavior With Class Constraint

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Jul 30 12:12:48 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by stephen at covidimus.net.

http://bugzilla.ximian.com/show_bug.cgi?id=75668

--- shadow/75668	2005-07-30 12:12:48.000000000 -0400
+++ shadow/75668.tmp.23103	2005-07-30 12:12:48.000000000 -0400
@@ -0,0 +1,65 @@
+Bug#: 75668
+Product: Mono: Compilers
+Version: 1.0
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: stephen at covidimus.net               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: GMCS Incorrect 'as' Operator Behavior With Class Constraint
+
+Description of Problem:
+
+Gmcs appears to recognize and accept a class constraint (where T:class) on
+a generic method, but the 'as' operator doesn't work as it should when the
+class constraint is applied.
+
+Code to Reproduce the Problem:
+
+ public static T QueryInterface<T>(object val)
+   where T : class
+ {
+     if (val == null)
+         return null;
+
+     // First, see if the given object can be directly cast
+     // to the requested type.  This will be a common case,
+     // especially when checking for standard behavior interface
+     // implementations (like IXrcDataElement).
+     T tval = val as T;
+     if (tval != null)
+         return tval;
+
+     // ... rest of method unimportant and omitted ...
+     return null;
+ }
+
+
+
+Actual Results:
+
+Xircle.Core/src/Core/XrcConvert.cs(118) error CS0077: The as operator
+should be used with a reference type only (T is a value type)
+
+Expected Results:
+
+The 'as' operator should compile without errors b/c the 'class' constraint
+(where T:class) on the method should cause T to be assumed to be a
+reference type.  Visual Studio beta 2 accepts this code without error.
+
+How often does this happen? 
+
+Every time.
+
+Additional Information:
+
+Bug #75368 appeared to me to be related, but even though it's marked as
+fixed, the problem still appears in SVN head, so perhaps it is not.


More information about the mono-bugs mailing list