Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs (C#)

Code before:
                //             r[0] :
                Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "0").WithLocation(13, 15),
                // (14,20): error CS8081: Expression does not have a name.
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_ExpressionHasNoName, "r[0]").WithLocation(14, 20),
                // (14,20): error CS8350: This combination of arguments to 'R<string>.this[in int]' is disallowed because it may expose variables referenced by parameter 'i' outside of their declaration scope
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_CallArgMixing, "r[0]").WithArguments("R<string>.this[in int]", "i").WithLocation(14, 20),
                // (14,22): error CS8156: An expression cannot be used in this context because it may not be passed or returned by reference
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "0").WithLocation(14, 22));
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/82474")]
        public void ColorColor_FieldInitializer()
        {
            var source = """
                #pragma warning disable CS0169, CS0414, CS0649 // unused field
                class C
                {
                    string F = nameof(D.M);
                    D D;
                }
                class D
                {
                    public void M() { }
                }
                """;
            CreateCompilation(source, parseOptions: TestOptions.RegularPreview).VerifyEmitDiagnostics();
            CreateCompilation(source, parseOptions: TestOptions.Regular12).VerifyEmitDiagnostics();
            CreateCompilation(source, parseOptions: TestOptions.Regular11).VerifyEmitDiagnostics();
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/82474")]
        public void ColorColor_Attribute()
        {
            var source = """
                #pragma warning disable CS0169 // unused field
                [A(nameof(D.M))] class C
                {
                    D D;
                }
                class D
                {
                    public void M() { }
                }
                class A : System.Attribute
                {
                    public A(string s) { }
                }
                """;

Review comment (suggestion):
>public void M() { } [](http://example.com/codeflow?start=20&length=19)

Consider also testing with static member #Closed

Code after:
                //             r[0] :
                Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "0").WithLocation(13, 15),
                // (14,20): error CS8081: Expression does not have a name.
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_ExpressionHasNoName, "r[0]").WithLocation(14, 20),
                // (14,20): error CS8350: This combination of arguments to 'R<string>.this[in int]' is disallowed because it may expose variables referenced by parameter 'i' outside of their declaration scope
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_CallArgMixing, "r[0]").WithArguments("R<string>.this[in int]", "i").WithLocation(14, 20),
                // (14,22): error CS8156: An expression cannot be used in this context because it may not be passed or returned by reference
                //             nameof(r[0]);
                Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "0").WithLocation(14, 22));
        }

        [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/82474")]
        public void ColorColor_FieldInitializer([CombinatorialValues("", "static")] string modifier)
        {
            var source = $$"""
                #pragma warning disable CS0169, CS0414, CS0649 // unused field
                class C
                {
                    string F = nameof(D.M);
                    D D;
                }
                class D
                {
                    public {{modifier}} void M() { }
                }
                """;
            CreateCompilation(source, parseOptions: TestOptions.RegularPreview).VerifyEmitDiagnostics();
            CreateCompilation(source, parseOptions: TestOptions.Regular12).VerifyEmitDiagnostics();
            CreateCompilation(source, parseOptions: TestOptions.Regular11).VerifyEmitDiagnostics();
        }

        [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/82474")]
        public void ColorColor_Attribute([CombinatorialValues("", "static")] string modifier)
        {
            var source = $$"""
                #pragma warning disable CS0169 // unused field
                [A(nameof(D.M))] class C
                {
                    D D;
                }
                class D
                {
                    public {{modifier}} void M() { }
                }
                class A : System.Attribute
                {
                    public A(string s) { }
                }
                """;