[Mono-list] Possible mcs bug: CS0019 detected for comparable instances

Rodolfo Campero rodolfocampero@hotmail.com
Sun, 19 Oct 2003 23:59:45 +0000

Hello Miguel,

>From: Miguel de Icaza <miguel@ximian.com>
>To: Rodolfo Campero <rodolfocampero@hotmail.com>
>CC: mono-list@lists.ximian.com
>Subject: Re: [Mono-list] Possible mcs bug: CS0019 detected for 
>Date: 19 Oct 2003 16:11:33 -0400
> > I'm trying to port an application I'm developing at work. Over there we 
> > Microsoft .Net SDK.
> > When I tried to compile it in mono I got:
> >
> > 	error CS0019: Operator != cannot be applied to operands of type `xxx' 
> > `yyy'
> >From my reading of the ECMA spec, this is a bug in the Microsoft C#
>Section 14.9.6 "Reference type equality operators" states that there
>must be a standard implicit conversion from the type of either operand
>to the type of the other operand.

Yes, you're right, I think I jumped over that statement when I read the 
spec... I filed the bug report because it works in Microsoft's csc, and I 
missintepreted the following quote (also from 14.9.6):

"It is a compile-time error to use the predefined reference type equality 
operators to compare two "references that are known to be different at 

I got confused by the part that reads "...that are *known* to be different 
at compile-time." In fact, as I wrote in a later email, is not possible to 
state at compile-time if an object referenced through the interface of a 
class not sealed implements another interface. But what I was missing is 
that the quoted text is just an implication of the rule; just because two 
references are _not known_ to be different at compile-time doesn't means 
that is OK to compare them directly.

Anyway, casting explicitly to "object" any of the two references that I'm 
trying to compare does the trick.

I apologise for the bug report, I should have been more careful and read the 
spec thoroughly. Sorry for the inconvenience.
> > I've narrowed down the problem and the smallest program which reproduces 
> > error is the following one:
> >
> > using System;
> > namespace Test {
> > 	public class Test {
> > 		public static void Main(string[] args) {
> > 			BaseClass baseRef = new DerivedClass();
> > 			ITest interfaceRef = (ITest)baseRef;
> > 			Console.WriteLine("Is this wrong? {0}", (interfaceRef!=baseRef));
> > 		}
> > 	}
> >
> > 	public interface ITest {}
> >
> > 	public class BaseClass {}
> >
> > 	public class DerivedClass: BaseClass, ITest {}
> > }
> >
>Mono-list maillist  -  Mono-list@lists.ximian.com

Yours sincerely,


STOP MORE SPAM with the new MSN 8 and get 2 months FREE*