Skip to content

Fix MA0194 merge with existing and-patterns#1162

Merged
meziantou merged 1 commit into
mainfrom
meziantou/ma0194-parentheses
May 18, 2026
Merged

Fix MA0194 merge with existing and-patterns#1162
meziantou merged 1 commit into
mainfrom
meziantou/ma0194-parentheses

Conversation

@meziantou
Copy link
Copy Markdown
Owner

Why

MA0194 did not merge some valid is expressions when one side already used a relational and pattern. It could also produce ambiguous output without explicit grouping when or combined with an and subpattern.

What changed

  • Reused existing pattern syntax in TryCreatePatternSyntax when Roslyn already provides a PatternSyntax, so relational patterns remain mergeable.
  • Updated parenthesizing logic to add parentheses for mixed precedence in both directions (and with or, and or with and).
  • Added a regression test (LogicalOr_ParenthesizeAndPattern) to verify:
    • marker is 0x01 || marker is >= 0xD0 and <= 0xD7
    • becomes marker is 0x01 or (>= 0xD0 and <= 0xD7).

Validation

  • dotnet test tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --filter "FullyQualifiedName~MergeIsPatternChecksAnalyzerTests" --nologo

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou enabled auto-merge (squash) May 18, 2026 20:44
@meziantou meziantou merged commit a40c61a into main May 18, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/ma0194-parentheses branch May 18, 2026 22:20
This was referenced May 18, 2026
This was referenced May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant