Consolidate expression-form context restriction diagnostics - #55614
Open
BillWagner wants to merge 3 commits into
Open
Consolidate expression-form context restriction diagnostics#55614BillWagner wants to merge 3 commits into
BillWagner wants to merge 3 commits into
Conversation
…8115, CS8185, CS8209, CS8310, CS8312) This article consolidates five compiler diagnostics related to invalid expression contexts: - CS8115: Throw expressions in restricted contexts - CS8185: Declaration expressions in restricted contexts - CS8209: Void-returning expression restrictions - CS8310: Operator binding for null/default/new - CS8312: Default literal target type requirements Content organized by remediation strategy. Codes removed from catch-all. CS8188 preserved in expression-tree-restrictions.md per issue guidance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request consolidates several C# compiler diagnostics about invalid expression forms/contexts into a single reference article, and wires the new article into the C# language reference navigation while removing the consolidated codes from the catch-all diagnostics page.
Changes:
- Added a new consolidated compiler-messages article:
expression-form-restrictions.md. - Added a TOC entry for the new article under C# language reference compiler messages.
- Removed the consolidated diagnostic codes from the catch-all “sorry we don’t have specifics” page.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md | Removes the consolidated diagnostic codes from the catch-all diagnostics list. |
| docs/csharp/language-reference/toc.yml | Adds a TOC entry for the consolidated “Expression-form restrictions” article. |
| docs/csharp/language-reference/compiler-messages/expression-form-restrictions.md | Introduces the consolidated guidance article for CS8115, CS8185, CS8209, CS8310, and CS8312. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+38
to
+44
| The compiler permits throw expressions only in specific contexts where an expression can appear and the exception is immediately propagated. Move the `throw` expression to a valid context, such as: | ||
|
|
||
| - A conditional arm of a ternary or switch expression (where the throw is one of the arms). | ||
| - An assignment to evaluate the throw in place of the assigned value. | ||
| - An argument to a method call where throwing is appropriate. | ||
| - A statement in a lambda or local function body (not within a method that must return a value). | ||
|
|
…context restrictions (CS0175, CS0186, CS1547) Consolidate three standalone diagnostic articles (CS0175, CS0186, CS1547) into expression-form-restrictions.md, broadening the article scope from 5 to 8 codes while maintaining thematic coherence: MERGED CODES: - CS0175: Use of keyword 'base' is not valid in this context - CS0186: Use of null is not valid in this context - CS1547: Keyword 'void' cannot be used in this context CHANGES: - Updated expression-form-restrictions.md with new 'Keyword and literal context restrictions' section containing substantive guidance from the three deleted standalone articles - Merged all unique remediation information and examples - Updated front matter f1_keywords and helpviewer_keywords (8 codes) - Updated master error list with all 8 codes and exact Roslyn messages - Updated TOC displayName with all 8 codes - Removed old TOC entries for CS0175, CS0186, CS1547 - Created three redirects from old paths to new destination anchors - Deleted three now-retired standalone files FOOTPRINT REDUCTION: 3 standalone files → 1 consolidated article VERIFICATION: - YAML front matter valid - All 8 codes present in f1_keywords/helpviewer_keywords - No trailing whitespace - Redirect JSON valid (1415 total entries) - Exact Roslyn messages preserved per Bill's requirements Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…OC entry The displayName folded scalar contained a duplicated five-code tail (CS8115, CS8185, CS8209, CS8310, CS8312 with associated phrases) left over from the original commit after the eight-code expansion appended new content without removing the old suffix. Co-authored-by: Copilot <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.
Closes #55339
Summary
Consolidates five compiler diagnostics related to invalid expression contexts into a single reference article:
expression-form-restrictions.md.Included Diagnostics
Changes
Created
docs/csharp/language-reference/compiler-messages/expression-form-restrictions.mdwith content organized by remediation strategy:Updated
docs/csharp/language-reference/toc.ymlto add TOC entry after "Lambda expressions"Removed all five codes from
docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.mdRelated Diagnostics
CS8188 (An expression tree may not contain a throw-expression) remains in
expression-tree-restrictions.mdper issue #55339 scope guidance.Exhaustive Follow-up Search
A comprehensive search of all 194 catch-all diagnostics and Roslyn source identified four additional candidates fitting a related but distinct theme (varargs
__arglistrestrictions: CS1636, CS1669, CS8362, CS8378). Per issue triage, these have been deferred as a separate future varargs-theme consolidation. Candidates CS8081, CS8082, and CS8092 were classified as orthogonal (nameof syntax, parse-level errors) and excluded.Standalone Diagnostic Article Consolidation Evaluation
Scope: Enumerating existing standalone
CS????.mdarticles for potential merge into this theme.Findings:
docs/csharp/language-reference/compiler-messages/anddocs/csharp/misc/Candidate Categories & Rationale for Exclusion:
Conclusion: The five-code article captures a unique, non-overlapping thematic scope: expressions whose syntactic form is prohibited in specific semantic contexts. Keeping the narrowly scoped five-code article aligns with the goal of shrinking article footprint through coherent thematic consolidation rather than forced merges.
Verification
Notes for Reviewers
This is the first consolidation under the expression-form theme. The article is complete and narrowly scoped to expression-form context restrictions triggered directly during binding and compilation, not ref-safety or escape-scope analysis.
Internal previews