You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# 7 §15.3.10.4 (Member names reserved for indexers) says that specific signatures of get_Item and set_Item are reserved, and that Item is a reserved member name, when the class has an indexer. However, if the indexer has an IndexerNameAttribute, then the name given in that attribute should be reserved instead of Item.
Example
usingSystem.Runtime.CompilerServices;publicclassC{[IndexerName("Slot")]intthis[inti]=>0;// The standard says that get_Item is a reserved member name,// and that declaring it here causes a compile-time error.// It should not be reserved in this case.intget_Item(inti)=>1;// Instead, get_Slot should be reserved.//int get_Slot(int i) => 2;}
Expected behavior
The example should not cause a compile-time error.
§15.3.10.4 (Member names reserved for indexers) should say that IndexerNameAttribute has this effect.
For invocations that occur within indexer accessors, the member name used is that supplied by an `IndexerNameAttribute` ([§22.6](attributes.md#226-attributes-for-interoperation)) on the indexer member, if present, or the default name `Item` otherwise.
And in §C.2 (Standard Library Types defined in ISO/IEC 23271):
usingSystem.Runtime.CompilerServices;classC1{// is allowed by a compiler[IndexerName("C1")]intthis[inti]=>0;}classC2{// error CS0542: 'C2': member names cannot be the same as their enclosing typeintC2=>0;}
Describe the bug
C# 7 §15.3.10.4 (Member names reserved for indexers) says that specific signatures of get_Item and set_Item are reserved, and that Item is a reserved member name, when the class has an indexer. However, if the indexer has an IndexerNameAttribute, then the name given in that attribute should be reserved instead of Item.
Example
Expected behavior
The example should not cause a compile-time error.
§15.3.10.4 (Member names reserved for indexers) should say that IndexerNameAttribute has this effect.
Additional context
Inspired by #1302.
IndexerNameAttribute is referenced under §22.5.5.4 (The CallerMemberName attribute):
csharpstandard/standard/attributes.md
Line 849 in 02d1a90
And in §C.2 (Standard Library Types defined in ISO/IEC 23271):
csharpstandard/standard/standard-library.md
Lines 429 to 432 in 02d1a90
The text was updated successfully, but these errors were encountered: