Skip to content

Commit

Permalink
Fix RCS1169 (#1092)
Browse files Browse the repository at this point in the history
Co-authored-by: Josef Pihrt <josef.pihrt@outlook.com>
  • Loading branch information
jamesHargreaves12 and josefpihrt authored Jun 1, 2023
1 parent 31bf7e7 commit bf2f6b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improve inversion of logical expressions to handling additional cases ([#1086](https://github.com/josefpihrt/roslynator/pull/1086)).
- Fix [RCS1084](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1084.md) ([#1085](https://github.com/josefpihrt/roslynator/pull/1085)).
- Fix [RCS1169](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1169.md) ([#1092](https://github.com/JosefPihrt/Roslynator/pull/1092)).

## [4.3.0] - 2023-04-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public override void VisitAssignedExpression(ExpressionSyntax expression)
{
SyntaxKind kind = expression.Kind();

if (kind == SyntaxKind.SuppressNullableWarningExpression)
{
var postfixUnaryExpression = (PostfixUnaryExpressionSyntax)expression;
expression = postfixUnaryExpression.Operand;
kind = expression.Kind();
}

if (kind == SyntaxKind.IdentifierName)
{
AnalyzeAssigned((IdentifierNameSyntax)expression);
Expand Down Expand Up @@ -130,10 +137,8 @@ public override void VisitRefExpression(RefExpressionSyntax node)
{
VisitAssignedExpression(expression);
}
else
{
base.VisitRefExpression(node);
}

base.VisitRefExpression(node);
}

public override void VisitLocalFunctionStatement(LocalFunctionStatementSyntax node)
Expand Down
27 changes: 27 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1169MakeFieldReadOnlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,33 @@ ref int M()
return ref _f;
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MakeFieldReadOnly)]
public async Task TestNoDiagnostic_SuppressNullableWarning()
{
await VerifyNoDiagnosticAsync(@"
class C
{
int _a;
void M(ref int x) {}
void M2() {M(ref _a!);}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MakeFieldReadOnly)]
public async Task TestNoDiagnostic_RefInRef()
{
await VerifyNoDiagnosticAsync(@"
using System.Runtime.CompilerServices;
class C
{
int _a;
ref int M2() {return ref Unsafe.Add(ref _a, 3);}
}
");
}
}

0 comments on commit bf2f6b8

Please sign in to comment.