Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix analyzer [RCS1172](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1172) ([PR](https://github.com/dotnet/roslynator/pull/1710))
- [CLI] Fix `loc` command ([PR](https://github.com/dotnet/roslynator/pull/1711))
- Exclude ref-field backed properties from [RCS1085](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1085) ([PR](https://github.com/dotnet/roslynator/pull/1718))

## [4.14.1] - 2025-10-05

Expand Down
5 changes: 5 additions & 0 deletions src/Analyzers/CSharp/Analysis/UseAutoPropertyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private static void AnalyzePropertyDeclaration(SyntaxNodeAnalysisContext context
return;
}

#if ROSLYN_4_4
if (fieldSymbol.RefKind is RefKind.Ref or RefKind.RefReadOnly)
return;
#endif

if (!CheckPreprocessorDirectives(property))
return;

Expand Down
26 changes: 26 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1085UseAutoPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,30 @@ private static void Write2(ref readonly ReadOnlySequence<byte> data, IBufferWrit
}
}");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseAutoProperty)]
public async Task TestNoDiagnostic_BackingFieldRef()
{
await VerifyNoDiagnosticAsync(
@"
public ref struct Example(ref int value1, ref int value2)
{
private ref int _value1 = ref value1;
private readonly ref int _value2 = ref value2;

public int Value1
{
get => _value1;
set => _value1 = value;
}

public int Value2
{
get => _value2;
set => _value2 = value;
}
}
"
);
}
}
Loading