Bug 323729 (MONO81044) - [GMCS] Missing exception from invalid cast.
Summary: [GMCS] Missing exception from invalid cast.
Status: RESOLVED FIXED
Alias: MONO81044
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.2
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-06 01:54 UTC by Miguel de Icaza
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:30:17 UTC


---- Reported by miguel@ximian.com 2007-03-05 18:54:18 MST ----

The following code should thrown an InvalidCastException at runtime, but
does not with Mono:

using System.Collections.Generic;

class CantCastGenericListToArray
{
	public static void Main(string[] args)
	{
		IList<object> list = new object[] { "foo", "bar" };
		string[] array = (string[])list;
		if (list.Count != array.Length)
		{
			throw new System.ApplicationException();
		}
	}
}



---- Additional Comments From vargaz@gmail.com 2007-03-06 06:38:41 MST ----

This is a gmcs/reflection bug. The same program compiled using csc
throws an exception on mono, and PEVerify reports errors on the gmcs
produced one.




---- Additional Comments From miguel@ximian.com 2007-03-06 12:01:05 MST ----

Just a question: shouldn't our verifier throw here with the invalid
generated code?



---- Additional Comments From lupus@ximian.com 2007-03-08 11:48:09 MST ----

Please attach either the buggy generated binary or the IL code so we
can add it to the verifier test suite. The test doesn't compile with
gmcs for me:
gmcs-invalidcast.cs(8,48): error CS0030: Cannot convert type
`System.Collections.Generic.IList<object>' to `string[]'




---- Additional Comments From lupus@ximian.com 2007-03-08 12:41:28 MST ----

Ok, with an updated gmcs it compiled: gmcs thinks it doesn't need to
insert a cast opcode when storing into array: this is most likely a
gmcs bug as doing the cast in IL code generates the exception.
As for the verifier: this check is currently missing
(mini.c:target_type_is_incompatible), mostly because it is likely to
trigger with some methods in the presence of interface vars.
I'll see if implementing the check makes at least a full bootstrap
working.



---- Additional Comments From martin@ximian.com 2007-04-03 15:10:26 MST ----

Fixed in SVN.


Unknown operating system unknown. Setting to default OS "Other".