[Mono-bugs] [Bug 457115] New: Compilation error when base class member is shadowed with different accessibility

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Dec 7 13:19:25 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=457115


           Summary: Compilation error when base class member is shadowed
                    with different accessibility
           Product: Mono: Compilers
           Version: 2.0.x
          Platform: x86-64
        OS/Version: openSUSE 11.0
            Status: NEW
          Severity: Minor
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: eylvisaker at physics.ucdavis.edu
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Description of Problem:
If a field is shadowed in derived class with less accessibility as the base
class, accessing the field in an instance of the derived class causes the
compiler to complain that the field is not accessible, which it should use the
base class field that has the appropriate accessibility.

Steps to reproduce the problem:
Compile the following code:

using System;

public class Base
{
    public int field
    {
        get { Console.WriteLine("Got from class Base."); return 0; }
    }
}
public class Derived : Base
{
    private new int field
    {
        get { Console.WriteLine("Got from class Derived."); return 1; }
    }
}

public class MainClass
{
    public static void Main()
    {
        Derived a = new Derived();

        Console.WriteLine("a = {0}", a.field);
    }
} 

Actual Results:
error CS0122: Derived.field is inaccessible due to protection level

Expected Results:
Compilation should succeed and output should be:
Got from class Base.
a = 0

How often does this happen? 
Every time the code example is compiled.

Additional Information:


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list