Bug 44168

Summary: Can use non-accessible member with nameof
Product: [Mono] Compilers Reporter: gsvick
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 4.4.2 (C7SR1)   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

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