Bug 39455 - Nameof operator doesn't handle sub-expressions
Summary: Nameof operator doesn't handle sub-expressions
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2016-03-08 17:47 UTC by Josh
Modified: 2016-04-14 06:32 UTC (History)
6 users (show)

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

Sample program illustrating the problem (457 bytes, text/plain)
2016-03-08 17:47 UTC, Josh

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:

Description Josh 2016-03-08 17:47:32 UTC
Created attachment 15311 [details]
Sample program illustrating the problem

Nameof does not handle sub-expressions in Xamarin Studio (stable or alpha).

Error text: "Error CS8082: An argument to nameof operator cannot include sub-expression (CS8082)"

We use this feature in Visual Studio with our Xamarin codebase, so being unable to when we open the project in Xamarin Studio is difficult.

3x images of Xamarin Studio Alpha & Stable, and VS15 here: http://imgur.com/a/F64I2
Comment 1 Marek Safar 2016-03-09 17:03:36 UTC
Fixed in master and mono 4.4
Comment 2 Aktar 2016-03-16 12:45:28 UTC
This issues was pushed in the alpha version released today (more info below).
Except that in this version the compiler will raise an exception for both of the methods in the sample : nameof(MyPerson.MyCar); and nameof(MyPerson.MyCar.Year);

"error CS8082: An argument to nameof operator cannot include sub-expression"

Xamarin Studio
Version 6.0 (build 4801)
Installation UUID: a3c95a91-ddc1-4bed-8905-cafe7ed7db25
	Mono 4.4.0 (mono-4.4.0-branch/f8474c4) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000040

Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Apple Developer Tools
Xcode 7.2.1 (9548.1)
Build 7C1002

Version: (Business Edition)
Hash: fa3b68c
Branch: master
Build date: 2016-03-09 11:44:54-0500

Version: (Business Edition)
Android SDK: /Users/aktar/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.0

Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Android Designer EPL code available here:

Xamarin Android Player
Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

Version: (Starter Edition)

Build Information
Release ID: 600004801
Git revision: f73f730c738baf8701a5892b7af64fd468d1dc0c
Build date: 2016-03-14 14:28:06-04
Xamarin addins: 3af7be6c701eb0137645a03e38b82f23b65738c3
Build lane: monodevelop-lion-cycle7

Operating System
Mac OS X 10.11.3
Darwin MacBook-Pro-de-Aktar.local 15.3.0 Darwin Kernel Version 15.3.0
    Thu Dec 10 18:40:58 PST 2015
    root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Comment 3 Marek Safar 2016-03-16 17:30:31 UTC
Is it really the exact code? I cannot reproduce it locally, the attached code compiles without error for me
Comment 4 Aktar 2016-03-17 12:31:53 UTC
The error will occur only on a variable, not on a field or a property.
Here my edited sample code :

namespace NameOfIssue
    public class Car
        public int Year { get; set; }

    public class Person
        public Car MyCar { get; set; }

    public class MainClass
        public static Person MyPerson = new Person();

        public static void Main(string[] args)

        public static void Good()
            var name = nameof(MyPerson.MyCar.Year);

        public static void Bad()
            var myPerson = new Person();
            var name = nameof(myPerson.MyCar.Year);
Comment 5 Marek Safar 2016-03-17 16:03:50 UTC
Fixed in master and Mono 4.4
Comment 6 Luca Weiss 2016-03-28 14:37:40 UTC
In which version is it fixed? I have the same bug in "Stable"
Comment 7 Marek Safar 2016-03-29 09:40:10 UTC alpha does not have the fix. You need to wait for next alpha or compile mono yourself
Comment 8 Luca Weiss 2016-03-29 14:40:57 UTC
Any ETA when the next alpha will be released?
Comment 9 Adrian Murphy 2016-04-07 19:39:05 UTC
We are hoping to release one later this week or early next week.
Comment 10 Luca Weiss 2016-04-07 19:39:37 UTC
Comment 11 shorter.david 2016-04-14 05:40:45 UTC
Any update on this, am having the issue.
Comment 12 Marek Safar 2016-04-14 06:32:53 UTC
It's fixed in Mono