Skip to content

Commit 8529360

Browse files
authored
Fix analyzer RCS1146 (#1747)
1 parent 1ff1786 commit 8529360

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- 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)
13+
- Fix analyzer [RCS1146](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1146) ([PR](https://github.com/dotnet/roslynator/pull/1747))
1314
- Fix analyzer [RCS1194](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1194) ([PR](https://github.com/dotnet/roslynator/pull/1733))
1415

1516
## [4.15.0] - 2025-12-14

src/Analyzers/CSharp/Analysis/UseConditionalAccessAnalyzer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ private static bool ValidateRightExpression(
331331
if (pattern is ConstantPatternSyntax constantPattern2)
332332
return constantPattern2.Expression.WalkDownParentheses().IsKind(SyntaxKind.NullLiteralExpression);
333333
}
334+
else if (pattern.IsKind(SyntaxKind.AndPattern))
335+
{
336+
return false;
337+
}
334338

335339
return true;
336340
}

src/Tests/Analyzers.Tests/RCS1146UseConditionalAccessTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,21 @@ void M()
10211021
}
10221022
", options: Options.AddConfigOption(ConfigOptionKeys.NullConditionalOperator_AvoidNegativeBooleanComparison, true));
10231023
}
1024+
1025+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseConditionalAccess)]
1026+
public async Task TestNoDiagnostic_AndPattern()
1027+
{
1028+
await VerifyNoDiagnosticAsync("""
1029+
class Foo
1030+
{
1031+
void M()
1032+
{
1033+
string data = null;
1034+
if (data != null && data.Length is not 2 and not 3)
1035+
{
1036+
}
1037+
}
1038+
}
1039+
""");
1040+
}
10241041
}

0 commit comments

Comments
 (0)