[Mono-bugs] [Bug 78961][Wis] New - [GMCS] runtime should support Covariant / Contravariant generic parameters
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Thu Jul 27 14:48:36 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 nazgul at omega.pl.
http://bugzilla.ximian.com/show_bug.cgi?id=78961
--- shadow/78961 2006-07-27 14:48:36.000000000 -0400
+++ shadow/78961.tmp.14040 2006-07-27 14:48:36.000000000 -0400
@@ -0,0 +1,95 @@
+Bug#: 78961
+Product: Mono: Runtime
+Version: 1.0
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: nazgul at omega.pl
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: [GMCS] runtime should support Covariant / Contravariant generic parameters
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+In .NET IL (but unfortunately not in C#) it is possible to mark generic
+parameters as covariant (+) or contravariant (-)
+It makes possible to convert generic classes to other versions with respect
+to their generic arguments (like IList<string> to IList<object>).
+According to .NET 2.0 spec it is allowed only for interfaces and delegates.
+
+Unfortunately this aspect of .NET specification is not implemented in Mono
+now. I present an example
+
+Steps to reproduce the problem:
+1. Run attached out.exe binary (you can obtain it also by compiling
+attached IL example)
+
+Actual Results:
+aa
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+ at Test.processObjects (ICovariantEnumerator`1 x) [0x00000]
+ at Test.Main () [0x00000]
+
+Expected Results:
+aa
+bb
+
+How often does this happen?
+Always
+
+Additional Information:
+The example is created by Nemerle compiler and works fine on MS.NET. The
+original code is:
+
+interface ICovariantEnumerator [+T]
+{
+ MoveNext () : bool;
+ Current : T { get; }
+}
+
+[Record]
+class Enumerator [T] : ICovariantEnumerator [T]
+{
+ enu : System.Collections.Generic.IEnumerator [T];
+
+ public MoveNext () : bool
+ {
+ enu.MoveNext ();
+ }
+
+ public Current : T {
+ get { enu.Current }
+ }
+}
+
+module Test {
+ public processObjects (x : ICovariantEnumerator [object]) : void {
+ _ = x.MoveNext ();
+ System.Console.WriteLine (x.Current);
+ }
+
+ public processStrings (x : ICovariantEnumerator [string]) : void {
+ _ = x.MoveNext ();
+ System.Console.WriteLine (x.Current);
+ }
+
+ public Main () : void
+ {
+ def x = System.Collections.Generic.List ();
+ x.Add ("aa");
+ x.Add ("bb");
+ def y = Enumerator (x.GetEnumerator ());
+ Test.processStrings (y);
+ Test.processObjects (y);
+ }
+}
More information about the mono-bugs
mailing list