Fix #3895: keep byref-like ToString in string concatenation#3896
Open
sailro wants to merge 1 commit into
Open
Conversation
String concatenation cannot box a byref-like value, so removing its explicit ToString call produces invalid C#. Preserve that call while retaining the surrounding string-concatenation reconstruction. Assisted-by: Copilot:gpt-5.6-sol:GitHub Copilot CLI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 86d2918e-5a24-48b4-9a86-41d331ec3720
sailro
force-pushed
the
fix-3894-span-concat
branch
from
July 19, 2026 23:02
c0f326f to
675fca8
Compare
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 #3895.
Problem
String-concatenation reconstruction removes explicit
ToString()calls when the C# compilerwould normally reproduce an equivalent call through the built-in
+operator.That assumption does not hold for byref-like values.
Span<T>andReadOnlySpan<T>cannot beconverted to
object, so removing the call from"prefix" + span.ToString()produces"prefix" + span, which fails with CS0019.Solution
Keep the explicit
ToString()call when its target is byref-like.The surrounding
string.Concatreconstruction still proceeds, so the result remains thenatural and compilable
"prefix" + span.ToString()form.Tests
Added a Roslyn 3+ Pretty fixture covering both
Span<char>andReadOnlySpan<char>.Validation:
StringConcatenationPretty matrix: 6 passedRelease solution build: 0 warnings, 0 errors
Full solution test suite: 4,891 passed, 15 existing skips
At least one test covering the code changed