Repository navigation
Brace a member body that holds only a block comment [patch] - #187
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
HasCode treated only // comments and directives as "not code", so a BodyFactory that wrote only a /* ... */ comment took the single-line branch and was placed on the declaration line: "void M() /* nothing to do */" (CS1002). The scanner now reports the characters inside every top-level comment, line or block, honouring string and character literals, and HasCode looks for code outside them, so a block-comment-only body is braced like a //-only one has been since #161. Fixes #185 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW1zLzNveHEn69h7Vn3
|
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 #185
Problem
TemplateRendering.HasCodetreated only//comments and#directives as "not code". ABodyFactorythat wrote only/* nothing to do */therefore counted as a one-line body of code and was placed on the declaration line:The
//form has been braced since #157/#161.Change
VerbatimStringScanner.FindCommentTextflags every character inside a top-level comment, line or block, delimiters included. It reuses the existing lexer walk, so a/*or//inside a string or character literal starts no comment, and an unterminated block comment runs to the end.HasCodenow looks for non-whitespace outside those comments on any line that is not a directive. The lines are scanned together, so a block comment spanning several lines is not code on any of them.FindCodeEnds/IsCode) is unchanged.Once #186 merges,
RenderExpressionwill also checkHasCode. A/* */-only expression body is then refused too, which closes the block-comment variant of #184. The two PRs touch different methods and each stands alone onmain.Tests
Five new tests in
TemplateTests:main: a single-line block comment, a multi-line block comment, and a block comment followed by a line comment (on a constructor)/* note */ => 1;still counts as code, and"/* not a comment */"inside a string is codeThe full suite passes: 334 tests. The local Sonar run reports nothing beyond the existing
S2699findings. AnS3776complexity hit on the first draft was fixed by moving the comment marking intoTrySkipCommentOrLiteral.Generated by Claude Code