Repository navigation
Brace a member body that holds only comments or directives [patch] - #161
Open
matt-edmondson wants to merge 2 commits into
Open
matt-edmondson wants to merge 2 commits into
matt-edmondson wants to merge 2 commits into
Conversation
WriteBody chose a body's shape by counting non-blank lines, so a body of
one line comment became an expression body ("void M() // note") and
two or more comment or #pragma lines were spliced below the declaration
with no braces. Either way the member had no body (CS1002). A body with
no line of code is now wrapped in a braced block; one-line bodies with
code still stay on the declaration line.
Fixes #157
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3C2EQ5hMiLw63t4Aa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3C2EQ5hMiLw63t4Aa
|
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 #157
What changed
TemplateRendering.WriteBodydecided a body's shape by counting non-blank lines. A line counted even when it was only a//comment or a#pragmadirective. So// nothing to resetbecamevoid M() // nothing to reset, and two or more such lines were spliced below the declaration with no braces. In both cases the member had no body, which gives CS1002.Now, when no line of the body holds code, the body is written as a braced block on the lines after the declaration, with the comments and directives kept inside it:
A line holds code when its text before any line comment is non-empty and does not start with
#. The comment boundary comes from the existingFindCodeEnds, the helperWriteExpressionBodyalready uses, so a//inside a string literal is not taken for a comment. A one-line body that does hold code, such as=> x;,{ }or=> x; // trailing, still stays on the declaration line.Tests
ConstructorTemplatebody, and an emptyPragmaScope.AOneLineBodyWithCodeStaysOnTheDeclarationLinepins the unchanged one-line shape.Generated by Claude Code