-
Notifications
You must be signed in to change notification settings - Fork 11
Description
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
- build(deps): bump github.com/goplus/gogen from 1.19.7 to 1.20.2 #615 - Dependency update PR that exposed this issue
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