Bug 44168 - Can use non-accessible member with nameof
Summary: Can use non-accessible member with nameof
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 4.4.2 (C7SR1)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-09-10 18:26 UTC by gsvick
Modified: 2016-09-16 09:01 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 gsvick 2016-09-10 18:26:21 UTC
When compiling this code:

    using System;
     
    public class Test
    {
        public static void Main()
        {
            Console.WriteLine(nameof(A.X));
            Console.WriteLine(nameof(A.Y));  // works fine, but shouldn't
        }
    }
     
    public class A
    {
        public int X;
        private int Y {get; set;}
    }

The Roslyn compiler fails with:

> error CS0122: 'A.Y' is inaccessible due to its protection level

The mcs compiler (I have tried the latest version from the download.mono-project.com repo on Ubuntu, which is 4.4.2.0) does not report any error and the resulting program runs fine. It should instead mirror the Roslyn compiler and fail during compilation.
Comment 1 Marek Safar 2016-09-16 09:01:42 UTC
Fixed in master and Mono 4.8