Mikioo / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Incorrect code when having private (or non-virtual) methods of same name in base class and derived class #302

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We have to classes like this:

  public class BaseClass
  {
    public void DoSomething()
    {
      Foo();
    }

    private void Foo()
    {
    }

  }

  public class DerivedClass : BaseClass
  {
    private void Foo()
    {
    }
  }

When executing  

  DerivedClass d = new DerivedClass();
  d.DoSomething();

we expect BaseClass.Foo() to be called from inside DoSomething(), but instead 
DerivedClass.Foo() is called,
just as if BaseClass.Foo was declared virtual and DerivedClass.Foo() was 
declared override.

The same happens when declaring Foo() slightly different (public and new)

  public class BaseClass
  {

    public void DoSomething()
    {
      Foo();
    }

    public void Foo()
    {
    }

  }

  public class DerivedClass : BaseClass
  {

    private new void Foo()
    {
    }
  }

Original issue reported on code.google.com by zoomer...@gmail.com on 11 Jul 2013 at 8:31

GoogleCodeExporter commented 9 years ago

Original comment by zoomer...@gmail.com on 11 Jul 2013 at 8:51