Concatenate adjacent string literals in deprecated attribute messages#728
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
A C deprecated message can be written as adjacent string literals, which the compiler concatenates into a single value. The generator extracted the text between the first and last quote verbatim, so the emitted Obsolete attribute contained the raw boundary quotes and inter-literal whitespace, producing invalid C#. Scan the attribute source for each literal and join their contents into a single valid Obsolete message. Fixes dotnet#694 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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 #694.
A C
deprecatedmessage can be written as adjacent string literals, which the compiler concatenates into a single value:The generator extracted the message as the substring between the first
"(viaIndexOf) and the last"(viaLastIndexOf) and emitted it verbatim. For adjacent literals that span text includes the interior boundary quotes and inter-literal whitespace/newlines, so it emitted invalid C#:The fix replaces the fragile first/last-quote slice with a proper scan (
GetDeprecatedMessage) that walks the attribute source, gathers the contents of every string literal (respecting escaped quotes so\"isn't treated as a terminator), and joins them into a single value:The common single-literal path is byte-identical (verified: no golden output changed), escaped quotes are preserved, and a missing/empty message still emits a bare
[Obsolete].Added
DeprecatedAdjacentStringTestcovering the adjacent-literal case. Build0 warning / 0 error(Release,TreatWarningsAsErrors+EnforceCodeStyleInBuild); full suite green (3713 passed / 0 failed).Note
This PR description and the code change were drafted by Copilot on my behalf.