Skip to content

fix(mutating): hoist mutations of target-typed interpolated strings - #4030

Closed
EnesKartal wants to merge 2 commits into
stryker-mutator:masterfrom
EnesKartal:fix/issue-3984
Closed

EnesKartal wants to merge 2 commits into
stryker-mutator:masterfrom
EnesKartal:fix/issue-3984

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #3984

Root cause

When an interpolated string is converted to an interpolated string handler (e.g. string.Create(CultureInfo.InvariantCulture, $"...") or StringBuilder.AppendLine($"...")) or to FormattableString / IFormattable, wrapping the argument itself in a conditional expression ((MutantControl.IsActive(0) ? $"" : $"...")) loses the target-typed conversion and fails compilation (e.g. CS1620 / CS1503).

Wrapping the conditional in an outer interpolated string ($"{(...)}") would also alter runtime behavior for IFormatProvider, FormattableString, and custom handlers because the inner interpolated string would be formatted into a string using the current culture before reaching the handler.

Fix

  • Added InterpolatedStringExpressionOrchestrator to detect interpolated string handler and FormattableString/IFormattable conversions via SemanticModel.GetConversion(node) (IsInterpolatedStringHandler || IsInterpolatedString) and store their string mutations at a higher control level while still mutating inner interpolation expressions in place.
  • Updated InvocationExpressionOrchestrator.InjectMutations to defer injection to the enclosing statement/block when the invocation is an ExpressionStatementSyntax or returns void, so calls like sb.AppendLine($"...") and void handler methods are controlled via if/else statements instead of invalid ternary expressions.

Tests

  • Added unit tests in CsharpMutantOrchestratorTests covering string.Create, inner interpolation mutations, StringBuilder.AppendLine expression statements, void expression-bodied handler methods, FormattableString.Invariant, and FormattableString local declarations.
  • Added an end-to-end compilation test in MutantAndCompileTests verifying all cases compile with zero diagnostics.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@dupdob

dupdob commented Nov 26, 2026

Copy link
Copy Markdown
Member

superseded by PR #4046 .
Thanks for your effort, but another PR was already in progress with what we though was a design more in line with the existing codebase

@dupdob dupdob closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String mutant of an interpolated string passed to string.Create(IFormatProvider, ref DefaultInterpolatedStringHandler) never compiles (CS1620)

3 participants