Skip to content

Bug: gogen v1.20.2 update exposes comment parsing issue causing test failures #618

@xgopilot

Description

@xgopilot

Summary

Upgrading github.com/goplus/gogen from v1.19.7 to v1.20.2 exposes a latent bug in llcppg's comment parsing logic that causes multi-line C block comments to generate invalid Go code.

Related PR

Problem Description

When processing C header files with multi-line block comments (/* ... */), llcppg generates invalid Go code that fails to compile with gogen v1.20.2 (though it happened to work with v1.19.7).

What Breaks

Go's ast.Comment documentation states that each Comment node represents "a single //-style or /*-style comment" - emphasis on "single". This means:

  • For // comments: Each line is a separate Comment node
  • For /* */ comments: The entire block must be a single Comment node

When multi-line block comments are incorrectly handled, the Go printer generates invalid syntax.

Minimal Reproduction

Input C Header (test.h)

/* Create an iterator for traversing a domain
   The domain NULL denotes the default domain */
void example_function();

Expected Behavior

Should generate valid Go code with properly formatted comments.

Actual Behavior with gogen v1.20.2

❌ Compilation error:

test.go:X:Y: expected declaration, found The

The word "The" from the second line appears where Go expects a declaration keyword, because the comment delimiters are malformed.

Behavior with gogen v1.19.7

✅ Worked (though the underlying issue existed)

Test Failures

With gogen v1.20.2, the following tests fail:

Test Error
TestFromTestdata/gettext expected declaration, found The
TestFromTestdata/gpgerror expected declaration, found '*'
TestFromTestdata/issue507 Multiple block comment syntax errors
TestFromTestdata/keepcomment comment not terminated

Why gogen v1.20.2 Exposed This

The gogen v1.19.8 release included a printer refactoring that synchronized with Go's upstream implementation. This made comment handling more strict and correct, exposing the latent bug in llcppg's comment parsing that previously went unnoticed.

Environment

  • Component: _xtool/internal/parser/parser.go - ParseComment() function
  • Affected by: gogen v1.20.2 (printer refactoring in v1.19.8)
  • Workaround: Stay on gogen v1.19.7 until fixed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesPull requests that update a dependency file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions