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 [EMAIL PROTECTED] http://bugzilla.ximian.com/show_bug.cgi?id=81277 --- shadow/81277 2007-03-30 15:32:48.000000000 -0500 +++ shadow/81277.tmp.13223 2007-03-30 15:32:48.000000000 -0500 @@ -0,0 +1,105 @@ +Bug#: 81277 +Product: Mono: Compilers +Version: 1.2 +OS: All +OS Details: all platforms +Status: NEW +Resolution: +Severity: +Priority: Normal +Component: C# +AssignedTo: [EMAIL PROTECTED] +ReportedBy: [EMAIL PROTECTED] +QAContact: [EMAIL PROTECTED] +TargetMilestone: --- +URL: +Cc: +Summary: Autoboxing an array of value types + +Description of Problem: + +I have a struct MyStruct that implements the IList<int> interface. gmcs +will not let me convert from MyStruct[] to IList<int>[]. I'm not sure if +this makes sense or not-- the ECMA spec doesn't talk explicitly about +autoboxing arrays of value types. The microsoft compiler forbids this +behavior. I think this is probably the correct behavior. + +On the other hand, gmcs *will* let me convert from MyStruct[] to +IList<IList<int>>. However, after compiling the code, when it gets run +with mono (or with the microsoft runtime), a System.NullReferenceException +gets thrown with the message "Object reference not set to an instance of an +object". The microsoft compiler will not let me convert from MyStruct[] to +IList<IList<int>>. + +I don't really know what the correct behavior is in the second case. The +ECMA spec doesn't explicitly forbid it, and it seems legal to me, but I +could be wrong. + +Steps to reproduce the problem: + +1. Compile the code below: + +########## START ############## + +using System; +using System.Collections; +using System.Collections.Generic; + +public struct MyStruct : IList<int> { + public int this [int x] { get { return 0; } set { return; } } + public int IndexOf (int x) { return 0; } + public void Insert (int x, int y) { return; } + public void RemoveAt (int x) { return; } + public int Count { get { return 0; } } + public bool IsReadOnly { get { return false; } } + public void Add (int x) { return; } + public void Clear () { return; } + public bool Contains (int x) { return false; } + public void CopyTo (int[] x, int y) { return; } + public bool Remove (int x) { return false; } + public IEnumerator<int> GetEnumerator() { yield return 0; } + IEnumerator IEnumerable.GetEnumerator() { yield return 0; } +} + +public class A { + + // This version does not compile: + public A(IList<int>[] x) { int y = x.Length; } + + // This version compiles fine, but results in an exception: + public A(IList<IList<int>> x) { int y = x.Count; } + +} + +public class Test { + static void Main () { + MyStruct[] myStructArray = new MyStruct[1]; + + Console.WriteLine("Trying to construct an A..."); + A a = new A(myStructArray); + Console.WriteLine("success!"); + } +} + +########## END ############## + +2. run with mono + +Actual Results: + +Trying to construct an A... + +Unhandled Exception: System.NullReferenceException: Object reference not +set to an instance of an object + at A..ctor (IList`1 x) [0x00000] + at Test.Main () [0x00000] + + +Expected Results: + +Trying to construct an A... +success! + +How often does this happen? + +always _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
