Bug 19378 - Warning about inherited field being hidden in mcs from 3.4.0, not in csc
Summary: Warning about inherited field being hidden in mcs from 3.4.0, not in csc
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-04-29 11:41 UTC by James Nugent
Modified: 2014-04-30 10:16 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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.