dotnet / dotnet/csharpstandard
CallerMemberNameAttribute on non-function member
- Dominant language
- C#
- Stars
- 815
- Forks
- 99
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
The standard does not specify what becomes the default value of a parameter decorated with CallerMemberNameAttribute when the parameter belongs to a constructor of an attribute, and a property or an indexer (or a type parameter of an indexer) is decorated with this attribute. (The standard specifies this if an *accessor* of a property or indexer is so decorated.)
C# 9 draft section 23.5.6.4 The CallerMemberName attribute.
**Example**
```csharp
using System;
using System.Runtime.CompilerServices;
public class MAttribute : Attribute {
public MAttribute(
[CallerMemberName]string? name = null) {
}
}
class C {
[M] object o = new MAttribute();
[M] object P {
[M] get => new MAttribute();
}
[M] object this[[M]int index] {
[M] get => new MAttribute();
}
[M] delegate void D<[M]T>();
}
```
**Expected behavior**
Should be equivalent to:
```csharp
class C {
[M(null)] object o = new MAttribute("o");
[M("P")] object P {
[M("P")] get => new MAttribute("P");
}
[M("Item")] object this[[M("Item")]int index] {
[M("Item")] get => new MAttribute("Item");
}
[M(null)] delegate void D<[M(null)]T>();
}
```
**Additional context**
Noticed from .
Contributor guide
Assessment
This issue has not been assessed yet.