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
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ private static PatternSyntax ParenthesizePatternIfNeeded(PatternSyntax pattern,
return pattern;

if (pattern is BinaryPatternSyntax binaryPattern &&
parentPatternKind is SyntaxKind.AndPattern &&
binaryPattern.Kind() is SyntaxKind.OrPattern)
(parentPatternKind, binaryPattern.Kind()) is (SyntaxKind.AndPattern, SyntaxKind.OrPattern) or (SyntaxKind.OrPattern, SyntaxKind.AndPattern))
{
return ParenthesizedPattern(pattern);
}
Expand Down Expand Up @@ -266,6 +265,12 @@ private static IOperation UnwrapOperation(IOperation operation)

private static bool TryCreatePatternSyntax(IPatternOperation patternOperation, out PatternSyntax patternSyntax)
{
if (patternOperation.Syntax is PatternSyntax patternFromSyntax)
{
patternSyntax = patternFromSyntax;
return true;
}

switch (patternOperation)
{
case IConstantPatternOperation constantPatternOperation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ enum MyEnum { Value1, Value2 }
.ValidateAsync();
}

[Fact]
public async Task LogicalOr_ParenthesizeAndPattern()
{
await CreateProjectBuilder()
.WithSourceCode("""
byte marker = 0;
_ = [|marker is 0x01 || marker is >= 0xD0 and <= 0xD7|];
""")
.ShouldFixCodeWith("""
byte marker = 0;
_ = marker is 0x01 or (>= 0xD0 and <= 0xD7);
""")
.ValidateAsync();
}

[Fact]
public async Task DifferentExpressions_DoNotReport()
{
Expand Down
Loading