[Mono-list] A compiler bug?

Atsushi Eno atsushi at ximian.com
Sun Jun 19 07:31:18 EDT 2005


Hello,

I think this is the expected behavior. What that code actually does is:

Console.WriteLine (
    cad1.Equals(cad2) + ",", // first argument
    + cad2.Equals(cad3) + "," + cad1.Equals(cad3)); // second argument

The second + is interpreted as an unary operator and thus it is correct
behavior of Console.WriteLine (since there is no {0} in the first
argument, the second argument is just ignored).

unary plus operator associated to System.String is not a violation
of C# specification. Note that any object can overload unary + operator.

Atsushi Eno

> Hello!
> 
> Look for the comma ',' inserted in the code I append
> (just next "cad1.Equals(cad2) +" in the seventh line).
> I think it should be a parser error, shouldn't be? But the compiler
> doesn't complain at all. The result with the comma is:
> 
> False,
> 
> and without the comma
> 
> False,False,True
> 
> I have probed this with mcs 1.1.8 and gmcs 1.1.5. The same output.
> 
> <code>
> using System;
> class X {
> 	static void Main () {
> 		string cad1 = "hello1";
> 		string cad2 = "bye";
> 		string cad3 = "hello1";
> 		Console.WriteLine (cad1.Equals(cad2) + ",", + cad2.Equals(cad3) + "," +
> cad1.Equals(cad3));
> 	}
> }
> </code>
> 
> Thank you!
> --
> Antonio Martínez
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list