Skip to content

A method body made only of a /* block comment */ is written as no body: void M() /* nothing to do */ (CS1002), unlike the // form fixed in #157 #185

Open

Description

@matt-edmondson

What happens

new MethodTemplate { Type = "void", Name = "M", BodyFactory = b => b.WriteLine("/* nothing to do */") }

This renders as:

void M() /* nothing to do */

That fails with CS1002 (; expected). The same body written as // nothing to do has rendered correctly since #157/#161:

void M()
{
	// nothing to do
}

Reproduced against main @ aa7ca53. Constructor and operator bodies take the same path.

Why

HasCode / IsCode (CodeBlocker/Templates/TemplateRendering.cs:454-483) treat as "not code" only // comments (found by VerbatimStringScanner.FindLineComments) and # directives. A block comment counts as code, so a one-line fragment takes the single-line branch at :311-316 and is placed on the declaration line as if it were an expression body.

Suggested fix

Have the scanner also report /* … */ spans, honouring strings and verbatim strings the way it does for //. Then treat a line that is only a block comment as not code in HasCode. That also closes the /* … */ variant of the comment-only expression-body issue.

Acceptance criteria

  • A BodyFactory that writes only /* … */, on one line or several, renders a braced body that compiles.
  • A body that writes /* note */ return 1; still counts as code and renders as it does today.
  • /* inside a string literal is not read as a comment.

Activity

  1. matt-edmondson commented on Nov 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions