-
Notifications
You must be signed in to change notification settings - Fork 11
fix: correct comment parsing for block comments and update gogen to v1.20.2 #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reproduction demonstrates the bug with pure gogen usage (no llcppg dependency). The bug: When multi-line block comments are split into multiple ast.Comment nodes (instead of keeping them as a single node), gogen generates malformed Go code with extra comment delimiters. Output comparison: - Buggy: Extra */ appears in generated code - Correct: Properly formatted block comment Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <[email protected]>
…1.20.2 This fixes issue #618 by properly handling multi-line C block comments according to Go's ast.Comment specification. Changes: - Fixed ParseComment() in _xtool/internal/parser/parser.go to keep block comments (/* ... */) as single ast.Comment nodes instead of splitting them by line - Line comments (//) continue to be split per line as expected - Updated gogen dependency from v1.19.7 to v1.20.2 The bug was exposed when gogen v1.20.2 became more spec-compliant with Go's standard ast printer behavior. The fix ensures llcppg generates valid Go code that compiles correctly with the updated gogen version. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <[email protected]>
|
@xgopilot check this compare test! llgo test ./_xtool/internal/...
shell: /usr/bin/bash -e {0}
env:
LLGO_ROOT: /home/runner/work/llcppg/llcppg/.llgo
PASS
PASS
PASS
PASS
--- FAIL: TestParserCppMode (0.40s)
--- FAIL: TestParserCppMode/comment (0.03s) |
✅ Fixed the comment testThe Root CauseThe PR fixed
However, the test's Changes MadeUpdated Before (incorrect - multi-line block comment split into 4 nodes): "List": [
{"Text": "/**\n"},
{"Text": " * doc 1\n"},
{"Text": " * doc 2\n"},
{"Text": " */\n"}
]After (correct - single node): "List": [
{"Text": "/**\n * doc 1\n * doc 2\n */\n"}
]Updated 4 occurrences of multi-line block comments in the test expectations:
CommitPushed commit |
The ParseComment() function was updated to keep multi-line block comments as a single ast.Comment node (per Go's AST spec) instead of splitting them by newlines. This commit updates the test expectations to match the new correct behavior. Changes: - Multi-line block comments (/* ... */) now appear as one Comment node - Line comments (//) continue to be separate nodes per line Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <[email protected]>
|
@xgopilot still have problem,check! llgo test ./_xtool/internal/...
shell: /bin/bash -e {0}
env:
LLGO_ROOT: /Users/runner/work/llcppg/llcppg/.llgo
PASS
PASS
PASS
PASS
--- FAIL: TestParserCppMode (0.40s)
--- FAIL: TestParserCppMode/comment (0.02s)
parser_test.testFrom:1: expect { |
Investigating test failure - need more details
|

Requested by @luoliwoshang
Fixes #618
Summary
This PR fixes the comment parsing bug that was exposed when upgrading gogen from v1.19.7 to v1.20.2. The issue caused multi-line C block comments to generate invalid Go code.
Changes
1. Fixed Comment Parsing Logic
Updated
_xtool/internal/parser/parser.goto correctly handle block comments according to Go's ast.Comment specification:/* ... */) are now kept as a singleast.Commentnode//) continue to be split per line as separate nodes2. Updated Dependencies
github.com/goplus/gogenfrom v1.19.7 to v1.20.2go.sumviago mod tidyTechnical Details
Root Cause: The
ParseComment()function was incorrectly splitting multi-line block comments by newline, creating separateast.Commentnodes for each line. This violated Go's ast specification which states that each Comment node represents "a single //-style or /*-style comment."Why gogen v1.20.2 Exposed This: gogen v1.19.8 (included in v1.20.2) synchronized its printer with Go's upstream implementation, making comment handling more strict and spec-compliant.
The Fix: Block comments are now kept as single nodes, preventing malformed Go code generation.
Testing
config,internal/name,internal/arg,internal/unmarshalreproduce_comment_bug.gofor debuggingExample
Before (buggy):
❌ Extra
*/causing invalid syntaxAfter (fixed):
✅ Properly formatted comment