Bug 19378

Summary: Warning about inherited field being hidden in mcs from 3.4.0, not in csc
Product: [Mono] Compilers Reporter: James Nugent <james>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description James Nugent 2014-04-29 11:41:50 UTC
The following code compiles without warnings using csc on Windows. However, with mcs from the 3.4.0 release, it gives the following warning:

Test.cs(26,45): warning CS0109: The member `MonoRepro.DerivedClass.InnerClass.AnInt' does not hide an inherited member. The new keyword is not required
Compilation succeeded - 1 warning(s)

Removing the "new" keyword from DerivedClass.InnerClass.AnInt results in the opposite warning from csc:

'Repro.DerivedClass.InnerClass.AnInt' hides inherited member 'Repro.DerivedClass.AnInt'. Use the new keyword if hiding was intended.

Whilst this is only a warning, it makes compiling on both Mono and .NET with warnings treated as errors very difficult.

Repro code:


namespace Repro
{
    public abstract class BaseClass
    {
        private static readonly int AnInt = 1;

        public static void PrintAnInt()
        {
            Console.WriteLine(AnInt);
        }
    }

    public abstract class DerivedClass : BaseClass
    {
        private static readonly int AnInt = 2;

        public static void PrintAnInt2()
        {
            Console.WriteLine(AnInt);
        }

        public class InnerClass : DerivedClass
        {
            private new static readonly int AnInt = 3;

            public static void PrintAnInt3()
            {
                Console.WriteLine(AnInt);
            }
        }
    }
}
Comment 1 Marek Safar 2014-04-29 13:52:55 UTC
Fixed in master
Comment 2 James Nugent 2014-04-30 06:43:51 UTC
Thanks for the quick response. That particular issue has been fixed, but now with master the following code gives the following warning.

Test2.cs(19,41): warning CS0108: `Repro3.Wrapper.DerivedClass.AnInt' hides inherited member `Repro3.BaseClass.AnInt'. Use the new keyword if hiding was intended
Test2.cs(7,37): (Location of the symbol related to previous warning)


This should not be given as the member in the base class is private.

```csharp
namespace Repro2
{
    public abstract class BaseClass
    {
        private static readonly int AnInt = 1;

        public static void PrintAnInt()
        {
            Console.WriteLine(AnInt);
        }
    }

    public static class Wrapper
    {
        public class DerivedClass : BaseClass
        {
            private static readonly int AnInt = 2;

            public static new void PrintAnInt()
            {
                Console.WriteLine(AnInt);
            }
        }
    }
}
```
Comment 3 Marek Safar 2014-04-30 10:16:17 UTC
Good observation. Fixed again.