dotnet / dotnet/roslyn

`value` parameter considered in scope in `nameof()` in event accessor attribute

Open
#73,733 0 comments 0 reactions 0 assignees View on GitHub
Area-Compilers
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: 17.9.7

**Steps to Reproduce**:

Compile the following:
```csharp
using System;

class A : Attribute
{
public A(string s) { }
}

class C
{
object P
{
[A(nameof(value))] set { } // error CS0103: The name 'value' does not exist in the current context
}

event EventHandler E
{
[A(nameof(value))] add { } // ok
[A(nameof(value))] remove { } // ok
}
}
```

**Expected Behavior**:
The same error reported for `[A(nameof(value))]` for event `add` and `remove` as property `set`.

**Actual Behavior**:
No error reported for `[A(nameof(value))]` on event `add` or `remove`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.