dotnet / dotnet/roslyn

Usage of obsolete backing field should be highlighted

Open
#80,277 4 comments 0 reactions 1 assignee Claimed by @333fred View on GitHub
Area-Compilers Feature - Field Keyword
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: latest main

**Steps to Reproduce**:
Test from `FieldKeywordTests.ObsoleteAttribute`, [sharplab](https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQAwAIpwHQCUCmAZgDb4DGALgJYD2AdgNzKzoDCyA3suj+gNoB5AEYBnGqQr4Aur1mYAzJjgA2dDSEArchXQAFOOg7oA5vh0BeAHzpCVfMWAN0Is4fQBfD9159b90OjCYhLSCkqq6lqUejBuphbWfg5OLjpGnu7ePIKi4mahcjxQipHaeopG8ehWNnbJzq7pXkiyvnUBQXmSMsVqmmW6ACxxrjVJjg1pHs3uQA=):
```
class C
{
[Obsolete] public static object P1 { get => field; set { } }
[field: Obsolete] public static object P2 { get => field; set { } }
[Obsolete] public object P3 { get => field; set { } }
[field: Obsolete] public object P4 { get => field; set { } }
}
```

**Diagnostic Id**: CS0612 `ErrorCode.WRN_DeprecatedSymbol`

**Expected Behavior**:
Usages of `field` in `P2` and `P4` are highlighted as soon as they are obsolete by `[field: Obsolete]` and we confirm that in test `ObsoleteAttribute` by outputting
```
C.k__BackingField: System.Runtime.CompilerServices.CompilerGeneratedAttribute,
C.k__BackingField: System.Runtime.CompilerServices.CompilerGeneratedAttribute, System.ObsoleteAttribute,
C.k__BackingField: System.Runtime.CompilerServices.CompilerGeneratedAttribute,
C.k__BackingField: System.Runtime.CompilerServices.CompilerGeneratedAttribute, System.ObsoleteAttribute,
```

**Actual Behavior**:
No highlighting

**Commentary**:
For some reason this behavior is fixed with test, but is it correct one? @cston

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.