Skip to content

Do not report MA0028 for concatenation of constant strings and chars - #1529

Merged
meziantou merged 1 commit into
mainfrom
feature/meziantou-analyzer-1528-8077de
Sep 18, 2026
Merged

meziantou merged 1 commit into
mainfrom
feature/meziantou-analyzer-1528-8077de

Conversation

@meziantou

Copy link
Copy Markdown
Owner

Fixes #1528

MA0028 reported sb.Append(" " + Const + " ") where Const is a const char, although the compiler merges this concatenation into a single string. The char operand is an implicit conversion rather than a constant string, and the left side is itself a nested concatenation, so the rule did not recognize it as constant.

Changes:

  • IsConstString now also accepts an implicit conversion of a constant char, and a string + whose operands are all constant (recursively).
  • Concatenations that include a non-constant value (e.g. "a" + 'b' + 10) are still reported.
  • Added tests and a note in docs/Rules/MA0028.md.

MA0028 tests pass on Roslyn 5.9 and 4.8.

@meziantou
meziantou merged commit 6a0b149 into main Sep 18, 2026
13 checks passed
@meziantou
meziantou deleted the feature/meziantou-analyzer-1528-8077de branch September 18, 2026 14:12
This was referenced Sep 18, 2026
This was referenced Oct 1, 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.

Do not report MA0028 for concatenation of constant strings and chars

1 participant