Bug 39455

Summary: Nameof operator doesn't handle sub-expressions
Product: [Mono] Compilers Reporter: Josh <lifecoder45>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: adrian.murphy, aktar, luca.weiss1, mono-bugs+monodevelop, mono-bugs+mono, shorter.david
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Sample program illustrating the problem

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
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/f8474c4) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000040

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

Apple Developer Tools
Xcode 7.2.1 (9548.1)
Build 7C1002

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

Xamarin.Android
Version: 6.1.0.16 (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:
https://github.com/xamarin/AndroidDesigner.EPL

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

Xamarin.Mac
Version: 2.8.0.58 (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 4.4.0.40/f8474c4"
Comment 7 Marek Safar 2016-03-29 09:40:10 UTC
4.4.0.40 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
Great!
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 4.4.0.122