Skip to content

Commit

Permalink
Fix analyzer RCS1085 (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed May 8, 2024
1 parent 1556d11 commit 69b5962
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix analyzer [RCS1246](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1246) ([PR](https://github.com/dotnet/roslynator/pull/1460))
- Fix analyzer [RCS1085](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1085) ([PR](https://github.com/dotnet/roslynator/pull/1461))

## [4.12.2] - 2024-04-23

Expand Down
2 changes: 1 addition & 1 deletion src/Analyzers/CSharp/Analysis/UseAutoPropertyAnalyzer.cs
Expand Up @@ -486,7 +486,7 @@ public override void VisitArgument(ArgumentSyntax node)
{
CancellationToken.ThrowIfCancellationRequested();

if (node.RefOrOutKeyword.IsKind(SyntaxKind.RefKeyword, SyntaxKind.OutKeyword))
if (node.RefOrOutKeyword.IsKind(SyntaxKind.RefKeyword, SyntaxKind.OutKeyword, SyntaxKind.InKeyword))
{
ExpressionSyntax expression = node.Expression?.WalkDownParentheses();

Expand Down
29 changes: 29 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1085UseAutoPropertyTests.cs
Expand Up @@ -952,4 +952,33 @@ class C
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseAutoProperty)]
public async Task TestNoDiagnostic_BackingFieldUsedByReference()
{
await VerifyNoDiagnosticAsync(@"
using System.Buffers;
class Repro(ReadOnlySequence<byte> data)
{
public ReadOnlySequence<byte> Data => _data;
private readonly ReadOnlySequence<byte> _data = data;
public void Method(IBufferWriter<byte> writer)
{
Write1(in _data, writer);
Write2(in _data, writer);
}
private static void Write1(in ReadOnlySequence<byte> data, IBufferWriter<byte> writer)
{
data.CopyTo(writer.GetSpan((int)data.Length));
}
private static void Write2(ref readonly ReadOnlySequence<byte> data, IBufferWriter<byte> writer)
{
data.CopyTo(writer.GetSpan((int)data.Length));
}
}");
}
}

0 comments on commit 69b5962

Please sign in to comment.