[Mono-list] Abstract classes...

Robert Remen Robert.Remen@nextranet.at
Thu, 27 May 2004 19:18:28 +0200


Hi!

The implementation of mono compiler is wrong. If you have a mix of
non-override and override overloads in a class, then the non-override
overload must take precedence (at compile time).

>From the C# Language Specification:

- in section 7.4.2:

"For example, the set of candidates for a method invocation does not
include methods marked override (Section 7.3), and methods in a base
class are not candidates if any method in a derived class is applicable
(Section 7.5.5.1)."

-in section 7.5.5.1:

"The intuitive effect of the resolution rules described above is as
follows: To locate the particular method invoked by a method invocation,
start with the type indicated by the method invocation and proceed up
the inheritance chain until at least one applicable, accessible,
non-override method declaration is found. Then perform overload
resolution on the set of applicable, accessible, non-override methods
declared in that type and invoke the method thus selected."

Robert



-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of vguzev
Sent: Donnerstag, 27. Mai 2004 17:39
To: mono-list@lists.ximian.com
Subject: [Mono-list] Abstract classes...

Hello!


I've found some differences between MS .Net and Mono behaviour.

Here's a little example (from RSDN forum):
8<---------------------------------------------------------
using System;

namespace TestMethods
{
 class Class1
 {
  static void Main(string[] args)
  {
   TestClass testClass =3D new TestClass();
   testClass.AddItem("", new TestParam());
   testClass.AddItem("", new ParamClass());

   BaseClass baseClass =3D testClass as BaseClass;
   baseClass.AddItem("", new TestParam());
   baseClass.AddItem("", new ParamClass());
  }
 }

 public class ParamClass {}

 public class TestParam : ParamClass {}

 public abstract class BaseClass
 {
  public abstract void AddItem(String name, ParamClass val);  }

 public class TestClass : BaseClass
 {
  public void AddItem(String name, Object val)
  {
   Console.WriteLine("Method with 'Object val' called");
  }

  public override void AddItem(String name, ParamClass val)
  {
   Console.WriteLine("Method with 'ParamClass val' called");
  }
 }
}
8<---------------------------------------------------------

MS.Net prints the following:
8<---------------------------------------------------------
Method with 'Object val' called
Method with 'Object val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
8<---------------------------------------------------------

Mono prints:
8<---------------------------------------------------------
Method with 'ParamClass val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
8<---------------------------------------------------------

Who is right? Mono or MS .Net?


Best regards,
Vadim B. Guzev
http://u.pereslavl.ru/~vadim/MCSharp/
_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list