Repository navigation
fix(mutating): hoist mutations of target-typed interpolated strings - #4030
Closed
EnesKartal wants to merge 2 commits into
Closed
EnesKartal wants to merge 2 commits into
EnesKartal wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
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.
Member
|
superseded by PR #4046 . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3984
Root cause
When an interpolated string is converted to an interpolated string handler (e.g.
string.Create(CultureInfo.InvariantCulture, $"...")orStringBuilder.AppendLine($"...")) or toFormattableString/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 forIFormatProvider,FormattableString, and custom handlers because the inner interpolated string would be formatted into astringusing the current culture before reaching the handler.Fix
InterpolatedStringExpressionOrchestratorto detect interpolated string handler andFormattableString/IFormattableconversions viaSemanticModel.GetConversion(node)(IsInterpolatedStringHandler || IsInterpolatedString) and store their string mutations at a higher control level while still mutating inner interpolation expressions in place.InvocationExpressionOrchestrator.InjectMutationsto defer injection to the enclosing statement/block when the invocation is anExpressionStatementSyntaxor returnsvoid, so calls likesb.AppendLine($"...")and void handler methods are controlled viaif/elsestatements instead of invalid ternary expressions.Tests
CsharpMutantOrchestratorTestscoveringstring.Create, inner interpolation mutations,StringBuilder.AppendLineexpression statements, void expression-bodied handler methods,FormattableString.Invariant, andFormattableStringlocal declarations.MutantAndCompileTestsverifying all cases compile with zero diagnostics.