From: Miguel de Icaza <[EMAIL PROTECTED]>
To: Rodolfo Campero <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: [Mono-list] Possible mcs bug: CS0019 detected for comparableinstances
Date: 19 Oct 2003 16:11:33 -0400
Hello,
> I'm trying to port an application I'm developing at work. Over there we use
> Microsoft .Net SDK.
> When I tried to compile it in mono I got:
>
> error CS0019: Operator != cannot be applied to operands of type `xxx' and
> `yyy'
>From my reading of the ECMA spec, this is a bug in the Microsoft C# compiler.
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 compile-time."
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.
Miguel
> I've narrowed down the problem and the smallest program which reproduces the
> 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 - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
Yours sincerely,
Rodolfo
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
_______________________________________________ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
