[Mono-list] casting reference arguments

Alan Jenkins sourcejedi@phonecoop.coop
Thu, 29 Jul 2004 11:44:42 +0000

I've found another case where the compiler should give a different error (at 
the moment it crashes).

public class Test {
	public static void Main ()
		byte b = 8;
		int i = 256;

		Increment (ref b);
		System.Console.WriteLine ("8 + 1 = {0}", b);

		Increment (ref i);
		System.Console.WriteLine ("256 + 1 = {0}", i);

	public static void Increment (ref int arg)
		arg += 1;

	public static void Increment (ref byte arg)
		// reference cast - not allowed
		Increment (ref (int) arg);

Who needs specifications to test against when you have a twisted mind?  
Seriouslly though, the above code could be legal - mcs might be expected to 
create a temporary variable of type int, assign the byte value to it, call 
the other Increment overload with it, and then assign its value back to the 
byte argument - so a check against the microsoft compiler is necessary.