[Mono-bugs] [Bug 78297][Nor] New - interface constraints to
generics are considered value types
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Thu May 4 22:07:43 EDT 2006
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 gregdavisfromnj at hotmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=78297
--- shadow/78297 2006-05-04 22:07:43.000000000 -0400
+++ shadow/78297.tmp.2298 2006-05-04 22:07:43.000000000 -0400
@@ -0,0 +1,54 @@
+Bug#: 78297
+Product: Mono: Compilers
+Version: 1.1
+OS: other
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com
+ReportedBy: gregdavisfromnj at hotmail.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: interface constraints to generics are considered value types
+
+Description of Problem:
+Create a generic container class of any type T, and assign null to a T.
+That is bad because T might be a value type. Constrain T to an arbitrary
+interface such as IAmNotAValueType, and that should guarantee that Ts are
+not value types. The compiler doesn't agree. Implementing that
+interface in AmNotAValueType, which is abstract, and only specifies
+abstract methods for IAmNotAValueType methods convinces the compiler to
+allow a null assignment to T. See the attached file.
+
+Steps to reproduce the problem:
+1. Make a generic class of type T whose only constraint on T is an
+interface.
+
+2. Assign null to a T someplace in the class; gmcs dissaproves.
+
+3. Make an abstract class whose only members are abstract, and which
+implements the aforementioned interface.
+
+4. Constrain T with the abstract class; gmcs is happy.
+
+Actual Results:
+Foobar.cs(25,5): error CS0403: Cannot convert null to the type parameter
+`T' becaues it could be a value type. Consider using `default (T)'
+instead.
+Foobar.cs(25,5): error CS0037: Cannot convert null to `T' because it is a
+value type
+Compilation failed: 2 error(s), 0 warnings
+
+Expected Results:
+a Foobar.dll
+
+How often does this happen?
+every time
+
+Additional Information:
+compile the attached file with "gmcs -target:library Foobar.cs"
More information about the mono-bugs
mailing list