Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix analyzer [RCS1118](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1118) to not report local variable passed as 'in' argument ([PR](https://github.com/dotnet/roslynator/pull/1782) by @NoahStolk)
- Fix analyzer [RCS1074](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1074) ([PR](https://github.com/dotnet/roslynator/pull/1768) by @cbersch)
- Fix enum contained flags check for partial matches in [RCS1258](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1258) ([PR](https://github.com/dotnet/roslynator/pull/1740) by @ovska)
- Fix analyzer [RCS1146](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1146) ([PR](https://github.com/dotnet/roslynator/pull/1747))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public override void VisitAssignedExpression(ExpressionSyntax expression)
Result = true;
}

public override void VisitArgument(ArgumentSyntax node)
{
if (node.RefKindKeyword.IsKind(SyntaxKind.InKeyword)
&& IsLocalReference(node.Expression))
{
Result = true;
}

base.VisitArgument(node);
}

public override void VisitIdentifierName(IdentifierNameSyntax node)
{
if (node.IsParentKind(SyntaxKind.SimpleMemberAccessExpression, SyntaxKind.AddressOfExpression)
Expand Down
66 changes: 66 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1118MarkLocalVariableAsConstTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,72 @@ public static int Bar(this ref int p1, int p2)
{
return p1 + p2;
}
}");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MarkLocalVariableAsConst)]
public async Task TestNoDiagnostic_InArgument()
Comment thread
josefpihrt marked this conversation as resolved.
{
await VerifyNoDiagnosticAsync(@"
public static class C
{
static void Foo()
{
int x = 0;
Bar(in x);
}

public static void Bar(in int p)
{
}
}");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MarkLocalVariableAsConst)]
public async Task TestNoDiagnostic_InArgument_RefReadOnlyParameter()
{
await VerifyNoDiagnosticAsync(@"
public static class C
{
static void Foo()
{
int x = 0;
Bar(in x);
}

public static void Bar(ref readonly int p)
{
}
}");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MarkLocalVariableAsConst)]
public async Task Test_InParameter_WithoutInKeyword()
{
await VerifyDiagnosticAndFixAsync(@"
public static class C
{
static void Foo()
{
[|int|] x = 0;
Bar(x);
}

public static void Bar(in int p)
{
}
}", @"
public static class C
{
static void Foo()
{
const int x = 0;
Bar(x);
}

public static void Bar(in int p)
{
}
}");
}
}
Loading