[Mono-bugs] [Bug 49287][Nor] New - Types that are arrays of interfaces cannot be compared with 'is' or 'as' operator

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 3 Oct 2003 12:28:54 -0400 (EDT)


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 cmars@ziplip.com.

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

--- shadow/49287	2003-10-03 12:28:54.000000000 -0400
+++ shadow/49287.tmp.29123	2003-10-03 12:28:54.000000000 -0400
@@ -0,0 +1,67 @@
+Bug#: 49287
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: Windows XP Professional SP1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: cmars@ziplip.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Types that are arrays of interfaces cannot be compared with 'is' or 'as' operator
+
+The 'is' and 'as' operators don't seem to work properly when testing for an
+array type, when that array type happens to be an array of interfaces.
+
+I discovered this problem when trying to run Bamboo.Prevalence 1.4 but
+created a simple app that demonstrates the inconsistency.  You can run it
+with Mono-0.28 and MS.NET to see the difference.  I'll attach a tarball of
+it as well.
+
+When the following is run with Mono-0.28, you get:
+The array is not null
+The array is not a IEnumerable[] when using 'is'
+The array is a IEnumerable[] when using IsAssignableFrom()
+I really got a System.Collections.IEnumerable[]
+
+When run with MS.NET, you get:
+The array is not null
+The array is a IEnumerable[] when using 'is'
+The array is a IEnumerable[] when using IsAssignableFrom()
+I really got a System.Collections.IEnumerable[]
+
+Compile with: mcs -out:IsAsMonoDemo.exe -target:exe -g IsAsMonoDemo.cs
+
+using System;
+using System.Collections;
+
+public class IsAsMonoDemo {
+	
+	public IsAsMonoDemo() {}
+	
+	static public void Main(string[] args) {
+		ArrayList al = new ArrayList();
+		for (int i = 0; i < 10; i++) {
+			al.Add(i.ToString());
+		}
+		
+		Console.WriteLine("ArrayList.Count=" + al.Count);
+		
+		object o = al.ToArray(typeof(IEnumerable));
+		Console.WriteLine("The array is " + (string)((o==null)?"null":"not null"));
+		Console.WriteLine("The array " + (string)((o is IEnumerable[])?"is":"is
+not") + " a string[] when using 'is'");
+		Console.WriteLine("The array " +
+(string)((typeof(IEnumerable[]).IsAssignableFrom(o.GetType()))?"is":"is
+not") + " a string[] when using IsAssignableFrom()");
+		Console.WriteLine("I really got a " + o.GetType());
+		
+	}
+	
+}